Skip to content
Snippets Groups Projects
Commit b5745730 authored by Lars Bilke's avatar Lars Bilke
Browse files

[CMake] Enable Windows shared libs support.

Everything works automatically except for global symbols where some manual work is required. See the BuildInfo example.
parent a19860df
No related branches found
No related tags found
No related merge requests found
...@@ -13,29 +13,31 @@ ...@@ -13,29 +13,31 @@
#include <string> #include <string>
#include "baselib_export.h"
namespace BaseLib namespace BaseLib
{ {
namespace BuildInfo namespace BuildInfo
{ {
extern const std::string build_timestamp; extern BASELIB_EXPORT const std::string build_timestamp;
extern const std::string cmake_cxx_compiler; extern BASELIB_EXPORT const std::string cmake_cxx_compiler;
extern const std::string cmake_cxx_flags; extern BASELIB_EXPORT const std::string cmake_cxx_flags;
extern const std::string cmake_cxx_flags_release; extern BASELIB_EXPORT const std::string cmake_cxx_flags_release;
extern const std::string cmake_cxx_flags_debug; extern BASELIB_EXPORT const std::string cmake_cxx_flags_debug;
extern const std::string git_version_sha1; extern BASELIB_EXPORT const std::string git_version_sha1;
extern const std::string git_version_sha1_short; extern BASELIB_EXPORT const std::string git_version_sha1_short;
extern const std::string git_describe; extern BASELIB_EXPORT const std::string git_describe;
extern const std::string ogs_version; extern BASELIB_EXPORT const std::string ogs_version;
extern const std::string source_path; extern BASELIB_EXPORT const std::string source_path;
extern const std::string geo_xml_schema_path; extern BASELIB_EXPORT const std::string geo_xml_schema_path;
extern const std::string app_xml_schema_path; extern BASELIB_EXPORT const std::string app_xml_schema_path;
extern const std::string data_path; extern BASELIB_EXPORT const std::string data_path;
extern const std::string data_binary_path; extern BASELIB_EXPORT const std::string data_binary_path;
extern const std::string tests_tmp_path; extern BASELIB_EXPORT const std::string tests_tmp_path;
} }
} }
...@@ -12,12 +12,16 @@ list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/BuildInfo.cpp" BuildInfo.h) ...@@ -12,12 +12,16 @@ list(APPEND SOURCES "${CMAKE_CURRENT_BINARY_DIR}/BuildInfo.cpp" BuildInfo.h)
# Create the library # Create the library
add_library(BaseLib ${SOURCES}) 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) set_target_properties(BaseLib PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(BaseLib PUBLIC logog) target_link_libraries(BaseLib PUBLIC logog)
if(MSVC) if(MSVC)
target_link_libraries(BaseLib PRIVATE WinMM) # needed for timeGetTime target_link_libraries(BaseLib PUBLIC WinMM) # needed for timeGetTime
endif() endif()
if(Qt5XmlPatterns_FOUND) if(Qt5XmlPatterns_FOUND)
......
...@@ -29,10 +29,13 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") ...@@ -29,10 +29,13 @@ elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
set(COMPILER_IS_MSVC TRUE CACHE INTERNAL "") set(COMPILER_IS_MSVC TRUE CACHE INTERNAL "")
endif() # CMAKE_CXX_COMPILER_ID 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) 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) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
# Enable Windows DLL support.
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif() endif()
# Set additional user-given compiler flags # Set additional user-given compiler flags
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment