diff options
Diffstat (limited to 'Tests/ConfigSources')
-rw-r--r-- | Tests/ConfigSources/CMakeLists.txt | 71 | ||||
-rw-r--r-- | Tests/ConfigSources/custom1.cpp.in | 13 | ||||
-rw-r--r-- | Tests/ConfigSources/custom2.cpp.in | 13 | ||||
-rw-r--r-- | Tests/ConfigSources/custom3.cpp.in | 13 | ||||
-rw-r--r-- | Tests/ConfigSources/custom4.cpp.in | 13 | ||||
-rw-r--r-- | Tests/ConfigSources/custom5.cpp.in | 13 | ||||
-rw-r--r-- | Tests/ConfigSources/main_debug.cpp | 9 | ||||
-rw-r--r-- | Tests/ConfigSources/main_other.cpp | 9 |
8 files changed, 150 insertions, 4 deletions
diff --git a/Tests/ConfigSources/CMakeLists.txt b/Tests/ConfigSources/CMakeLists.txt index 1db00cc..5513af8 100644 --- a/Tests/ConfigSources/CMakeLists.txt +++ b/Tests/ConfigSources/CMakeLists.txt @@ -16,6 +16,72 @@ void config_$<CONFIG>() {} ]] ) +# Custom command outputs named with the configuration(s). +add_custom_command( + OUTPUT "custom1_$<CONFIG>.cpp" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/custom1.cpp.in" "custom1_$<CONFIG>.cpp" + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/custom1.cpp.in + VERBATIM + ) +# Output path starts in a generator expression. +add_custom_command( + OUTPUT "$<1:custom2_$<CONFIG>.cpp>" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/custom2.cpp.in" "custom2_$<CONFIG>.cpp" + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/custom2.cpp.in + VERBATIM + ) +# Source file generated as a custom command's byproduct. +add_custom_command( + OUTPUT custom3.txt + BYPRODUCTS "$<1:custom3_$<CONFIG>.cpp>" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/custom3.cpp.in" "custom3_$<CONFIG>.cpp" + COMMAND ${CMAKE_COMMAND} -E touch custom3.txt + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/custom3.cpp.in + VERBATIM + ) +# Source file generated as a custom target's byproduct. +add_custom_target(custom4 + BYPRODUCTS "custom4_$<CONFIG>.cpp" + COMMAND ${CMAKE_COMMAND} -E copy_if_different "${CMAKE_CURRENT_SOURCE_DIR}/custom4.cpp.in" "custom4_$<CONFIG>.cpp" + VERBATIM + ) +# Source file generated by appended custom command. +add_custom_command( + OUTPUT "custom5_$<CONFIG>.cpp" + COMMAND ${CMAKE_COMMAND} -E echo custom5_$<CONFIG>.cpp + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/custom5.cpp.in + VERBATIM + ) +add_custom_command(APPEND + OUTPUT "custom5_$<CONFIG>.cpp" + COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/custom5.cpp.in" "custom5_$<CONFIG>.cpp.in" + VERBATIM + ) +# Appending through any configuration's output affects all configurations. +if(CMAKE_CONFIGURATION_TYPES MATCHES ";([^;]+)$") + set(last_config "${CMAKE_MATCH_1}") +else() + set(last_config ${CMAKE_BUILD_TYPE}) +endif() +add_custom_command(APPEND + OUTPUT "custom5_${last_config}.cpp" + COMMAND ${CMAKE_COMMAND} -E copy "custom5_$<CONFIG>.cpp.in" "custom5_$<CONFIG>.cpp" + VERBATIM + ) +foreach(n RANGE 1 5) + set_property(SOURCE custom${n}_Debug.cpp PROPERTY COMPILE_DEFINITIONS CUSTOM_CFG_DEBUG) + foreach(other Release RelWithDebInfo MinSizeRel) + set_property(SOURCE custom${n}_${other}.cpp PROPERTY COMPILE_DEFINITIONS CUSTOM_CFG_OTHER) + endforeach() +endforeach() +add_library(Custom STATIC + custom1_$<CONFIG>.cpp + custom2_$<CONFIG>.cpp + custom3_$<CONFIG>.cpp custom3.txt + custom4_$<CONFIG>.cpp + custom5_$<CONFIG>.cpp + ) + # Per-config sources via INTERFACE_SOURCES. add_library(iface INTERFACE) target_sources(iface INTERFACE @@ -34,7 +100,7 @@ add_executable(ConfigSources $<$<CONFIG:NotAConfig>:does_not_exist.cpp> ${CMAKE_CURRENT_BINARY_DIR}/config_$<CONFIG>.cpp ) -target_link_libraries(ConfigSources iface) +target_link_libraries(ConfigSources Custom iface) # Per-config sources via LINK_LIBRARIES. add_library(iface_debug INTERFACE) @@ -53,6 +119,7 @@ target_compile_definitions(ConfigSourcesLink PRIVATE "$<$<NOT:$<CONFIG:Debug>>:CFG_OTHER>" ) target_link_libraries(ConfigSourcesLink PRIVATE + Custom "$<$<CONFIG:Debug>:iface_debug>" "$<$<NOT:$<CONFIG:Debug>>:iface_other>" "$<$<CONFIG:NotAConfig>:iface_does_not_exist>" @@ -70,7 +137,7 @@ target_compile_definitions(ConfigSourcesLinkIface PRIVATE "$<$<CONFIG:Debug>:CFG_DEBUG>" "$<$<NOT:$<CONFIG:Debug>>:CFG_OTHER>" ) -target_link_libraries(ConfigSourcesLinkIface ConfigSourcesIface) +target_link_libraries(ConfigSourcesLinkIface Custom ConfigSourcesIface) # A target with sources in only one configuration that is not the # first in CMAKE_CONFIGURATION_TYPES. diff --git a/Tests/ConfigSources/custom1.cpp.in b/Tests/ConfigSources/custom1.cpp.in new file mode 100644 index 0000000..e5f21c7 --- /dev/null +++ b/Tests/ConfigSources/custom1.cpp.in @@ -0,0 +1,13 @@ +#ifdef CUSTOM_CFG_DEBUG +int custom1_debug() +{ + return 0; +} +#endif + +#ifdef CUSTOM_CFG_OTHER +int custom1_other() +{ + return 0; +} +#endif diff --git a/Tests/ConfigSources/custom2.cpp.in b/Tests/ConfigSources/custom2.cpp.in new file mode 100644 index 0000000..438c1fd --- /dev/null +++ b/Tests/ConfigSources/custom2.cpp.in @@ -0,0 +1,13 @@ +#ifdef CUSTOM_CFG_DEBUG +int custom2_debug() +{ + return 0; +} +#endif + +#ifdef CUSTOM_CFG_OTHER +int custom2_other() +{ + return 0; +} +#endif diff --git a/Tests/ConfigSources/custom3.cpp.in b/Tests/ConfigSources/custom3.cpp.in new file mode 100644 index 0000000..4545b69 --- /dev/null +++ b/Tests/ConfigSources/custom3.cpp.in @@ -0,0 +1,13 @@ +#ifdef CUSTOM_CFG_DEBUG +int custom3_debug() +{ + return 0; +} +#endif + +#ifdef CUSTOM_CFG_OTHER +int custom3_other() +{ + return 0; +} +#endif diff --git a/Tests/ConfigSources/custom4.cpp.in b/Tests/ConfigSources/custom4.cpp.in new file mode 100644 index 0000000..8a8b2a8 --- /dev/null +++ b/Tests/ConfigSources/custom4.cpp.in @@ -0,0 +1,13 @@ +#ifdef CUSTOM_CFG_DEBUG +int custom4_debug() +{ + return 0; +} +#endif + +#ifdef CUSTOM_CFG_OTHER +int custom4_other() +{ + return 0; +} +#endif diff --git a/Tests/ConfigSources/custom5.cpp.in b/Tests/ConfigSources/custom5.cpp.in new file mode 100644 index 0000000..51f40ae --- /dev/null +++ b/Tests/ConfigSources/custom5.cpp.in @@ -0,0 +1,13 @@ +#ifdef CUSTOM_CFG_DEBUG +int custom5_debug() +{ + return 0; +} +#endif + +#ifdef CUSTOM_CFG_OTHER +int custom5_other() +{ + return 0; +} +#endif diff --git a/Tests/ConfigSources/main_debug.cpp b/Tests/ConfigSources/main_debug.cpp index 9b1e68a..ef776f8 100644 --- a/Tests/ConfigSources/main_debug.cpp +++ b/Tests/ConfigSources/main_debug.cpp @@ -7,7 +7,14 @@ #include "iface.h" +extern int custom1_debug(); +extern int custom2_debug(); +extern int custom3_debug(); +extern int custom4_debug(); +extern int custom5_debug(); + int main(int argc, char** argv) { - return iface_src() + iface_debug(); + return iface_src() + iface_debug() + custom1_debug() + custom2_debug() + + custom3_debug() + custom4_debug() + custom5_debug(); } diff --git a/Tests/ConfigSources/main_other.cpp b/Tests/ConfigSources/main_other.cpp index 3184a19..74f2156 100644 --- a/Tests/ConfigSources/main_other.cpp +++ b/Tests/ConfigSources/main_other.cpp @@ -7,7 +7,14 @@ #include "iface.h" +extern int custom1_other(); +extern int custom2_other(); +extern int custom3_other(); +extern int custom4_other(); +extern int custom5_other(); + int main(int argc, char** argv) { - return iface_src() + iface_other(); + return iface_src() + iface_other() + custom1_other() + custom2_other() + + custom3_other() + custom4_other() + custom5_other(); } |