diff options
author | Deniz Bahadir <dbahadir@benocs.com> | 2020-09-22 12:04:26 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-09-23 14:05:55 (GMT) |
commit | 2f76e7429b96ae05e5f63d6458555a06b19c62e5 (patch) | |
tree | 8496837a64a4165fa340017e45d6fc43bcaa780b /Tests/ConfigSources | |
parent | d575ecc9dedd214ebd941913b81124a674be5008 (diff) | |
download | CMake-2f76e7429b96ae05e5f63d6458555a06b19c62e5.zip CMake-2f76e7429b96ae05e5f63d6458555a06b19c62e5.tar.gz CMake-2f76e7429b96ae05e5f63d6458555a06b19c62e5.tar.bz2 |
OBJECT libraries: Properly recognize if sources depend on configuration
Fixes: #21198
Diffstat (limited to 'Tests/ConfigSources')
-rw-r--r-- | Tests/ConfigSources/CMakeLists.txt | 17 | ||||
-rw-r--r-- | Tests/ConfigSources/shared.cpp | 8 |
2 files changed, 24 insertions, 1 deletions
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt index 6e69e8b..7b1a312 100644 --- a/Tests/ConfigSources/CMakeLists.txt +++ b/Tests/ConfigSources/CMakeLists.txt @@ -8,7 +8,12 @@ project(ConfigSources CXX) # Source file(s) named with the configuration(s). file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/config_$<CONFIG>.cpp" - CONTENT "void config_$<CONFIG>() {}\n" + CONTENT [[ +#if defined(_WIN32) && defined(OBJ_SHARED) +__declspec(dllexport) +#endif +void config_$<CONFIG>() {} +]] ) # Per-config sources via INTERFACE_SOURCES. @@ -76,3 +81,13 @@ else() endif() add_library(OneConfigOnly OBJECT "$<$<CONFIG:${one_config}>:${CMAKE_CURRENT_SOURCE_DIR}/iface_src.cpp>") set_property(TARGET OneConfigOnly PROPERTY LINKER_LANGUAGE CXX) + + +# --------------------------------------------------------------------------- +# Makes sure that each configuration uses the correct generated file. +add_library(ObjLibFromGeneratedSources OBJECT) +set_property(TARGET ObjLibFromGeneratedSources PROPERTY POSITION_INDEPENDENT_CODE 1) +target_compile_definitions(ObjLibFromGeneratedSources PRIVATE OBJ_SHARED) +target_sources(ObjLibFromGeneratedSources PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/config_$<CONFIG>.cpp) +add_library(SharedLibFromObjLibFromGeneratedSources SHARED shared.cpp) +target_link_libraries(SharedLibFromObjLibFromGeneratedSources PRIVATE ObjLibFromGeneratedSources) diff --git a/Tests/ConfigSources/shared.cpp b/Tests/ConfigSources/shared.cpp new file mode 100644 index 0000000..1726c46 --- /dev/null +++ b/Tests/ConfigSources/shared.cpp @@ -0,0 +1,8 @@ +#if defined(_WIN32) +# define EXPORT __declspec(dllexport) +#else +# define EXPORT +#endif +EXPORT void shared() +{ +} |