diff --git a/meson.build b/meson.build
index bb7488f490a21f4be744ba14491808edb7ec7323..558499ae7a3447264ce12ce60b04e8603ae38c2a 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 0d69a65dfea512eef11b40e206c1a4128b5c3bf3..ff8b1283e7c64efb6aed784e39ad250c1b6a3ad4 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')