From b5745730c07e3c17c79dcd1df5ffa3a7cc1fddf8 Mon Sep 17 00:00:00 2001 From: Lars Bilke <lars.bilke@ufz.de> Date: Fri, 12 May 2017 12:49:10 +0200 Subject: [PATCH] [CMake] Enable Windows shared libs support. Everything works automatically except for global symbols where some manual work is required. See the BuildInfo example. --- BaseLib/BuildInfo.h | 32 ++++++++++++++++--------------- BaseLib/CMakeLists.txt | 6 +++++- scripts/cmake/CompilerSetup.cmake | 7 +++++-- 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/BaseLib/BuildInfo.h b/BaseLib/BuildInfo.h index cc888557d63..1f0febe9ea5 100644 --- a/BaseLib/BuildInfo.h +++ b/BaseLib/BuildInfo.h @@ -13,29 +13,31 @@ #include <string> +#include "baselib_export.h" + namespace BaseLib { namespace BuildInfo { - extern const std::string build_timestamp; + extern BASELIB_EXPORT const std::string build_timestamp; - extern const std::string cmake_cxx_compiler; - extern const std::string cmake_cxx_flags; - extern const std::string cmake_cxx_flags_release; - extern const std::string cmake_cxx_flags_debug; + extern BASELIB_EXPORT const std::string cmake_cxx_compiler; + extern BASELIB_EXPORT const std::string cmake_cxx_flags; + extern BASELIB_EXPORT const std::string cmake_cxx_flags_release; + extern BASELIB_EXPORT const std::string cmake_cxx_flags_debug; - extern const std::string git_version_sha1; - extern const std::string git_version_sha1_short; + extern BASELIB_EXPORT const std::string git_version_sha1; + extern BASELIB_EXPORT const std::string git_version_sha1_short; - extern const std::string git_describe; - extern const std::string ogs_version; + extern BASELIB_EXPORT const std::string git_describe; + extern BASELIB_EXPORT const std::string ogs_version; - extern const std::string source_path; - extern const std::string geo_xml_schema_path; - extern const std::string app_xml_schema_path; - extern const std::string data_path; - extern const std::string data_binary_path; - extern const std::string tests_tmp_path; + extern BASELIB_EXPORT const std::string source_path; + extern BASELIB_EXPORT const std::string geo_xml_schema_path; + extern BASELIB_EXPORT const std::string app_xml_schema_path; + extern BASELIB_EXPORT const std::string data_path; + extern BASELIB_EXPORT const std::string data_binary_path; + extern BASELIB_EXPORT const std::string tests_tmp_path; } } diff --git a/BaseLib/CMakeLists.txt b/BaseLib/CMakeLists.txt index 377ac3b07a3..7feb6db73c2 100644 --- a/BaseLib/CMakeLists.txt +++ b/BaseLib/CMakeLists.txt @@ -12,12 +12,16 @@ list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/BuildInfo.cpp" BuildInfo.h) # Create the library add_library(BaseLib ${SOURCES}) +include(GenerateExportHeader) +generate_export_header(BaseLib) +target_include_directories(BaseLib PUBLIC ${CMAKE_CURRENT_BINARY_DIR}) + set_target_properties(BaseLib PROPERTIES LINKER_LANGUAGE CXX) target_link_libraries(BaseLib PUBLIC logog) if(MSVC) - target_link_libraries(BaseLib PRIVATE WinMM) # needed for timeGetTime + target_link_libraries(BaseLib PUBLIC WinMM) # needed for timeGetTime endif() if(Qt5XmlPatterns_FOUND) diff --git a/scripts/cmake/CompilerSetup.cmake b/scripts/cmake/CompilerSetup.cmake index 445216304f2..c313832dd53 100644 --- a/scripts/cmake/CompilerSetup.cmake +++ b/scripts/cmake/CompilerSetup.cmake @@ -29,10 +29,13 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") set(COMPILER_IS_MSVC TRUE CACHE INTERNAL "") endif() # CMAKE_CXX_COMPILER_ID -# When static libraries are used in some shared libraries it is required that -# also the static libraries have position independent code. if(BUILD_SHARED_LIBS) + # When static libraries are used in some shared libraries it is required + # that also the static libraries have position independent code. set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) + + # Enable Windows DLL support. + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE) endif() # Set additional user-given compiler flags -- GitLab