diff options
Diffstat (limited to 'Tests')
5 files changed, 84 insertions, 0 deletions
diff --git a/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake b/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake index 9ba3c85..c00f78b 100644 --- a/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake +++ b/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake @@ -1,5 +1,14 @@ include(RunCMake) +function(run_build name) + set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake(${name}) + run_cmake_command(${name}-build ${CMAKE_COMMAND} --build . --config Debug) + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) +endfunction() + run_cmake(unitybuild_c) run_cmake(unitybuild_c_batch) run_cmake(unitybuild_c_group) @@ -15,6 +24,9 @@ run_cmake(unitybuild_c_no_unity_build) run_cmake(unitybuild_c_no_unity_build_group) run_cmake(unitybuild_order) run_cmake(unitybuild_invalid_mode) +run_build(unitybuild_anon_ns) +run_build(unitybuild_anon_ns_no_unity_build) +run_build(unitybuild_anon_ns_group_mode) function(run_test name) set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${name}-build) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns.cmake new file mode 100644 index 0000000..6f4878f --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns.cmake @@ -0,0 +1,11 @@ +project(unitybuild_anon_ns CXX) + +include(${CMAKE_CURRENT_SOURCE_DIR}/unitybuild_anon_ns_test_files.cmake) + +write_unity_build_anon_ns_test_files(srcs) + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) + +set_target_properties(tgt PROPERTIES UNITY_BUILD_UNIQUE_ID MY_ANON_ID) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_group_mode.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_group_mode.cmake new file mode 100644 index 0000000..a91fc74 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_group_mode.cmake @@ -0,0 +1,19 @@ +project(unitybuild_anon_ns_group_mode CXX) + +include(${CMAKE_CURRENT_SOURCE_DIR}/unitybuild_anon_ns_test_files.cmake) + +write_unity_build_anon_ns_test_files(srcs) + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON + UNITY_BUILD_MODE GROUP) + +set_target_properties(tgt PROPERTIES UNITY_BUILD_UNIQUE_ID MY_ANON_ID) + +set_source_files_properties(s1.cpp s2.cpp s5.cpp s7.cpp s8.cpp + PROPERTIES UNITY_GROUP "a" + ) +set_source_files_properties(s3.cpp s4.cpp s6.cpp + PROPERTIES UNITY_GROUP "b" + ) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_no_unity_build.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_no_unity_build.cmake new file mode 100644 index 0000000..9f0a9e1 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_no_unity_build.cmake @@ -0,0 +1,11 @@ +project(unitybuild_anon_ns_no_unity_build CXX) + +include(${CMAKE_CURRENT_SOURCE_DIR}/unitybuild_anon_ns_test_files.cmake) + +write_unity_build_anon_ns_test_files(srcs) + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD OFF) + +set_target_properties(tgt PROPERTIES UNITY_BUILD_UNIQUE_ID MY_ANON_ID) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_test_files.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_test_files.cmake new file mode 100644 index 0000000..06a600e --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns_test_files.cmake @@ -0,0 +1,31 @@ + +function(write_unity_build_anon_ns_test_files OUTVAR) + set(srcs) + foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cpp") + file(WRITE "${src}" " +#ifndef CONFIG_H +#define CONFIG_H +#define MY_ANON_NAMESPACE MY_ANON_ID +#define MY_ANON(Name) MY_ANON_NAMESPACE::Name +#define MY_ANON_USING_NAMESPACE using namespace MY_ANON_NAMESPACE +#endif + +namespace { namespace MY_ANON_NAMESPACE { + int i = ${s}; +}} +int use_plain_${s}() { + return MY_ANON_NAMESPACE::i; +} +int func_like_macro_${s}() { + return MY_ANON(i); +} +int using_macro_${s}() { + MY_ANON_USING_NAMESPACE; + return i; +} +") + list(APPEND srcs "${src}") + endforeach() + set(${OUTVAR} ${srcs} PARENT_SCOPE) +endfunction() |