From 9d1fbbbc96705410a662af5858ca4df8a40796e9 Mon Sep 17 00:00:00 2001 From: mrsmidge Date: Wed, 30 Sep 2020 23:29:50 +0100 Subject: Fix static builds on MSVC --- CMakeLists.txt | 28 ++++++++++++++++------------ include/djinterop/config.hpp.in | 9 +++++++++ include/djinterop/meson.build | 3 +++ meson.build | 9 ++++++--- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 06f992e..22e0e25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ # The meson/ninja build should be preferred in all other cases. # cmake_minimum_required(VERSION 3.13) -project(libdjinterop VERSION 0.14.1) +project(libdjinterop VERSION 0.14.2) # Require C++17 set(CMAKE_CXX_STANDARD 17) @@ -22,14 +22,6 @@ option(SYSTEM_SQLITE "Use system installation of SQLite" ON) # Require zlib >= 1.2.8 find_package(ZLIB 1.2.8 REQUIRED) -# Generate config.hpp based on build-time environment. -include(CheckIncludeFileCXX) -CHECK_INCLUDE_FILE_CXX(optional DJINTEROP_STD_OPTIONAL) -CHECK_INCLUDE_FILE_CXX(experimental/optional DJINTEROP_STD_EXPERIMENTAL_OPTIONAL) -configure_file( - include/djinterop/config.hpp.in - include/djinterop/config.hpp) - add_library( djinterop src/djinterop/impl/crate_impl.cpp @@ -61,9 +53,20 @@ add_library( src/djinterop/transaction_guard.cpp src/djinterop/util.cpp) -target_compile_definitions( - djinterop PUBLIC - DJINTEROP_SOURCE) +target_compile_definitions(djinterop PUBLIC DJINTEROP_SOURCE) + +get_target_property(djinterop_library_type djinterop TYPE) +if(djinterop_library_type STREQUAL "STATIC_LIBRARY") + set(DJINTEROP_STATIC ON) +endif() + +# Generate config.hpp based on build-time environment. +include(CheckIncludeFileCXX) +CHECK_INCLUDE_FILE_CXX(optional DJINTEROP_STD_OPTIONAL) +CHECK_INCLUDE_FILE_CXX(experimental/optional DJINTEROP_STD_EXPERIMENTAL_OPTIONAL) +configure_file( + include/djinterop/config.hpp.in + include/djinterop/config.hpp) target_include_directories( djinterop PUBLIC @@ -76,6 +79,7 @@ target_link_libraries( djinterop PUBLIC ${ZLIB_LIBRARIES}) + if(SYSTEM_SQLITE) # Search for system installation of SQLite and use that. find_package(SQLite3 3.11.0 REQUIRED) diff --git a/include/djinterop/config.hpp.in b/include/djinterop/config.hpp.in index b558501..4783904 100644 --- a/include/djinterop/config.hpp.in +++ b/include/djinterop/config.hpp.in @@ -23,10 +23,19 @@ #error This library needs at least a C++17 compliant compiler #endif +// Statement about whether the library was built/installed as static or shared. +#cmakedefine DJINTEROP_STATIC + #if defined _WIN32 || defined __CYGWIN__ +#if defined DJINTEROP_STATIC +#define DJINTEROP_SYMBOL_IMPORT +#define DJINTEROP_SYMBOL_EXPORT +#define DJINTEROP_SYMBOL_LOCAL +#else #define DJINTEROP_SYMBOL_IMPORT __declspec(dllimport) #define DJINTEROP_SYMBOL_EXPORT __declspec(dllexport) #define DJINTEROP_SYMBOL_LOCAL +#endif #else #if __GNUC__ >= 4 #define DJINTEROP_SYMBOL_IMPORT __attribute__((visibility("default"))) diff --git a/include/djinterop/meson.build b/include/djinterop/meson.build index c43a0b2..1ec6646 100644 --- a/include/djinterop/meson.build +++ b/include/djinterop/meson.build @@ -4,6 +4,9 @@ # of configure_file() does not, at the time of writing (meson 0.55.0), support # writing the output file to a different directory. conf_data = configuration_data() +if default_library_type == 'static' + conf_data.set10('DJINTEROP_STATIC', true) +endif if cpp_compiler.has_header('optional') conf_data.set10('DJINTEROP_STD_OPTIONAL', true) endif diff --git a/meson.build b/meson.build index ea2e18d..ad10f25 100644 --- a/meson.build +++ b/meson.build @@ -1,9 +1,9 @@ project( 'djinterop', 'cpp', 'c', - version: '0.14.1', + version: '0.14.2', license: 'LGPL-3.0', - default_options: ['cpp_std=c++17', 'default_library=both']) + default_options: ['cpp_std=c++17', 'default_library=shared']) cpp_compiler = meson.get_compiler('cpp') @@ -13,10 +13,13 @@ if cpp_compiler.get_id() == 'msvc' endif # Set hidden visibility arguments for everything the project, if available. -if get_option('default_library') != 'static' +default_library_type = get_option('default_library') +if default_library_type != 'static' if cpp_compiler.has_argument('-fvisibility=hidden') add_global_arguments('-fvisibility=hidden', language: ['c', 'cpp']) endif +else + add_global_arguments('-DDJINTEROP_STATIC', language: 'cpp') endif -- cgit v1.2.3