From 595a7ac93209d6a74c49852970d9de6f0da4e673 Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Mon, 11 May 2020 21:25:06 +0200
Subject: [PATCH] meson.build update

---
 meson.build       | 52 +++++++++++++++++++++++------------------------
 meson_options.txt |  2 ++
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/meson.build b/meson.build
index bb7488f4..558499ae 100644
--- a/meson.build
+++ b/meson.build
@@ -90,34 +90,28 @@ manpath = custom_target( 'manpath'
                        , output: 'manpath.c'
                        , input: 'meson.build'
                        , command: [ find_program('sh'), '-c', 'echo \'const char *man_executable_path = "\'"$(which man)"\'";\' > @OUTPUT@' ] )
-common_deps = [ declare_dependency(
-  link_with: [ static_library( 'common'
-    , files(common_sources)
-    , manpath
-    , include_directories: includes ) ] ) ]
 
-lib = shared_library( 'lektor'
+common_deps = [ declare_dependency( link_with: [ static_library( 'common'
+                                  , files(common_sources), manpath
+                                  , include_directories: includes ) ] ) ]
+
+xxd = generator( find_program('xxd')
+               , output: '@BASENAME@.c'
+               , arguments: [ '-i', '@INPUT@', '@OUTPUT@' ] )
+
+lib = both_libraries( 'lektor'
                     , files(core_sources + mthread_sources)
-                    , [ custom_target( 'sqlinit'
-                                     , output: 'sqlinit.c'
-                                     , input: 'src/database/disk.sql'
-                                     , command: [ find_program('xxd'), '-i', '@INPUT@', '@OUTPUT@' ] ) ]
-                    , [ custom_target( 'sqlmemory'
-                                     , output: 'sqlmemory.c'
-                                     , input: 'src/database/memory.sql'
-                                     , command: [ find_program('xxd'), '-i', '@INPUT@', '@OUTPUT@' ] ) ]
+                    , xxd.process('src/database/disk.sql')
+                    , xxd.process('src/database/memory.sql')
                     , manpath
                     , include_directories: includes
                     , dependencies: [ core_deps, libdl, common_deps ] )
 
-bin_deps = [ declare_dependency( link_with: lib, include_directories: includes) ]
-
-# Client executable
-lkt = executable( 'lkt'
-                , files('src/main/lkt.c', 'src/cmd.c', 'src/common.c')
-                , manpath
-                , include_directories: includes
-                , install: true )
+if get_option('static_liblektor')
+  bin_deps = [ declare_dependency( link_with: lib.get_static_lib(), include_directories: includes) ]
+else
+  bin_deps = [ declare_dependency( link_with: lib.get_shared_lib(), include_directories: includes) ]
+endif
 
 # X11 window module
 if get_option('module_x11').enabled()
@@ -147,11 +141,18 @@ if get_option('module_sdl').enabled()
   endif
 endif
 
-modules_dep = declare_dependency( link_with: lektor_modules )
 srv = executable( meson.project_name() + 'd'
                 , files('src/main/server.c')
                 , include_directories: includes
-                , dependencies: [ bin_deps, modules_dep ]
+                , dependencies: [ declare_dependency( link_with: lektor_modules )
+                                , bin_deps ]
+                , install: true )
+
+# Client executable
+lkt = executable( 'lkt'
+                , files('src/main/lkt.c', 'src/cmd.c', 'src/common.c')
+                , manpath
+                , include_directories: includes
                 , install: true )
 
 # Man pages
@@ -170,6 +171,3 @@ foreach man: man_files
                , install: true
                , install_dir: join_paths(get_option('mandir'), 'man@0@'.format(man_section)) )
 endforeach
-
-# Install
-# meson.add_install_script('scripts/install.sh')
diff --git a/meson_options.txt b/meson_options.txt
index 0d69a65d..ff8b1283 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -3,3 +3,5 @@ option('static_modules', type: 'feature', value: 'enabled'
 
 option('module_sdl', type: 'feature', value: 'enabled', description: 'Build the sdl module')
 option('module_x11', type: 'feature', value: 'enabled', description: 'Build the x11 module')
+
+option('static_liblektor', type: 'boolean', value: true, description: 'Link the liblektor statically')
-- 
GitLab