diff --git a/CMakeLists.txt b/CMakeLists.txt index f6bec5752..1151ec21f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -146,6 +146,10 @@ else() endif() endif() +#============================================================================ +# Ask whether we should make a shared or static library. +option(BUILD_SHARED_LIBS "Set this to true to generate shared libraries (recommended), or false for static libraries" ON) + ##################################### # Handle CFlags unset (CMAKE_C_FLAGS_ALL CACHE) diff --git a/cmake/SDFUtils.cmake b/cmake/SDFUtils.cmake index 525c4d4c6..21ac67827 100644 --- a/cmake/SDFUtils.cmake +++ b/cmake/SDFUtils.cmake @@ -52,8 +52,11 @@ endmacro (BUILD_WARNING) ################################################# macro (sdf_add_library _name) set(LIBS_DESTINATION ${PROJECT_BINARY_DIR}/src) - set_source_files_properties(${ARGN} PROPERTIES COMPILE_DEFINITIONS "BUILDING_DLL") - add_library(${_name} SHARED ${ARGN}) + add_library(${_name} ${ARGN}) + set_target_properties(${_name} PROPERTIES DEFINE_SYMBOL "BUILDING_SDFORMAT_SHARED") + if(NOT BUILD_SHARED_LIBS) + target_compile_definitions(${_name} PUBLIC SDFORMAT_STATIC_DEFINE) + endif() set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${LIBS_DESTINATION}) if (MSVC) set_target_properties( ${_name} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${LIBS_DESTINATION}) diff --git a/include/sdf/system_util.hh b/include/sdf/system_util.hh index a94b9f46e..c2488dbb9 100644 --- a/include/sdf/system_util.hh +++ b/include/sdf/system_util.hh @@ -26,20 +26,13 @@ */ #if defined _WIN32 || defined __CYGWIN__ - #ifdef BUILDING_DLL - #ifdef __GNUC__ - #define SDFORMAT_VISIBLE __attribute__ ((dllexport)) - #else - #define SDFORMAT_VISIBLE __declspec(dllexport) - #endif + #ifdef BUILDING_SDFORMAT_SHARED + #define SDFORMAT_VISIBLE __declspec(dllexport) + #elif !defined SDFORMAT_STATIC_DEFINE + #define SDFORMAT_VISIBLE __declspec(dllimport) #else - #ifdef __GNUC__ - #define SDFORMAT_VISIBLE __attribute__ ((dllimport)) - #else - #define SDFORMAT_VISIBLE __declspec(dllimport) - #endif + #define SDFORMAT_VISIBLE #endif - #define SDFORMAT_HIDDEN #else #if __GNUC__ >= 4 && !defined SDFORMAT_STATIC_DEFINE #define SDFORMAT_VISIBLE __attribute__ ((visibility ("default")))