diff options
Diffstat (limited to 'Tests/RunCMake/UnityBuild')
45 files changed, 608 insertions, 0 deletions
diff --git a/Tests/RunCMake/UnityBuild/CMakeLists.txt b/Tests/RunCMake/UnityBuild/CMakeLists.txt new file mode 100644 index 0000000..77030d6 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.15) +project(${RunCMake_TEST} NONE) +include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake b/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake new file mode 100644 index 0000000..c00f78b --- /dev/null +++ b/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake @@ -0,0 +1,42 @@ +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) +run_cmake(unitybuild_cxx) +run_cmake(unitybuild_cxx_group) +run_cmake(unitybuild_c_and_cxx) +run_cmake(unitybuild_c_and_cxx_group) +run_cmake(unitybuild_batchsize) +run_cmake(unitybuild_default_batchsize) +run_cmake(unitybuild_skip) +run_cmake(unitybuild_code_before_and_after_include) +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) + set(RunCMake_TEST_NO_CLEAN 1) + run_cmake(${name}) + run_cmake_command(${name}-build ${CMAKE_COMMAND} --build . --config Debug) + run_cmake_command(${name}-test ${CMAKE_CTEST_COMMAND} -C Debug) + unset(RunCMake_TEST_BINARY_DIR) + unset(RunCMake_TEST_NO_CLEAN) +endfunction() + +run_test(unitybuild_runtest) +run_test(unitybuild_object_library) diff --git a/Tests/RunCMake/UnityBuild/f.c b/Tests/RunCMake/UnityBuild/f.c new file mode 100644 index 0000000..d5813c6 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/f.c @@ -0,0 +1,5 @@ +int f(int x) +{ + (void)x; + return 0; +} diff --git a/Tests/RunCMake/UnityBuild/f.cxx b/Tests/RunCMake/UnityBuild/f.cxx new file mode 100644 index 0000000..d5813c6 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/f.cxx @@ -0,0 +1,5 @@ +int f(int x) +{ + (void)x; + return 0; +} diff --git a/Tests/RunCMake/UnityBuild/func.c b/Tests/RunCMake/UnityBuild/func.c new file mode 100644 index 0000000..b14c907 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/func.c @@ -0,0 +1,6 @@ +#include "func.h" + +int func(void) +{ + return 0; +} diff --git a/Tests/RunCMake/UnityBuild/func.h b/Tests/RunCMake/UnityBuild/func.h new file mode 100644 index 0000000..563a980 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/func.h @@ -0,0 +1,6 @@ +#ifndef func_h +#define func_h + +extern int func(void); + +#endif diff --git a/Tests/RunCMake/UnityBuild/main.c b/Tests/RunCMake/UnityBuild/main.c new file mode 100644 index 0000000..19c18d4 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/main.c @@ -0,0 +1,6 @@ +#include "func.h" + +int main(void) +{ + return func(); +} diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns-build-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns-build-check.cmake new file mode 100644 index 0000000..746be32 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns-build-check.cmake @@ -0,0 +1,10 @@ +set(unitybuild_0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_cxx.cxx") + +file(STRINGS ${unitybuild_0} src) + +foreach(expectedRegex IN ITEMS "SRC_f\\.cxx" "BLD_s1\\.cpp") + if(NOT "${src}" MATCHES "${expectedRegex}") + set(RunCMake_TEST_FAILED "Generated unity file doesn't have a match for expected unity ID regex ${expectedRegex}") + return() + endif() +endforeach() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_anon_ns.cmake b/Tests/RunCMake/UnityBuild/unitybuild_anon_ns.cmake new file mode 100644 index 0000000..e05863d --- /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 f.cxx ${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() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_batchsize-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_batchsize-check.cmake new file mode 100644 index 0000000..72cc2b9 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_batchsize-check.cmake @@ -0,0 +1,11 @@ +set(unitybuild_c0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +set(unitybuild_c1 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_1_c.c") +if(NOT EXISTS "${unitybuild_c0}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c0} does not exist.") + return() +endif() + +if(NOT EXISTS "${unitybuild_c1}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c1} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_batchsize.cmake b/Tests/RunCMake/UnityBuild/unitybuild_batchsize.cmake new file mode 100644 index 0000000..7caf251 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_batchsize.cmake @@ -0,0 +1,16 @@ +project(unitybuild_batchsize C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt + PROPERTIES + UNITY_BUILD ON + UNITY_BUILD_BATCH_SIZE 4 +) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c-check.cmake new file mode 100644 index 0000000..024286d --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c-check.cmake @@ -0,0 +1,5 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +if(NOT EXISTS "${unitybuild_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c.cmake new file mode 100644 index 0000000..77a09cb --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c.cmake @@ -0,0 +1,12 @@ +project(unitybuild_c C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx-check.cmake new file mode 100644 index 0000000..269d545 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx-check.cmake @@ -0,0 +1,11 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +if(NOT EXISTS "${unitybuild_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c} does not exist.") + return() +endif() + +set(unitybuild_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_cxx.cxx") +if(NOT EXISTS "${unitybuild_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_cxx} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx.cmake new file mode 100644 index 0000000..073aff2 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx.cmake @@ -0,0 +1,17 @@ +project(unitybuild_c_and_cxx C CXX) + +set(srcs "") +foreach(s RANGE 1 8) + set(src_c "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src_c}" "int s${s}(void) { return 0; }\n") + + set(src_cxx "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cxx") + file(WRITE "${src_cxx}" "int s${s}(void) { return 0; }\n") + + list(APPEND srcs "${src_c}") + list(APPEND srcs "${src_cxx}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group-check.cmake new file mode 100644 index 0000000..b027682 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group-check.cmake @@ -0,0 +1,42 @@ +set(unitybuild_a_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_a_c.c") +if(NOT EXISTS "${unitybuild_a_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_a_c} does not exist.") + return() +else() + #verify that the 4 c file is part of this grouping and therefore UNITY_BUILD_BATCH_SIZE + #was ignored + file(STRINGS ${unitybuild_a_c} unitybuild_a_c_strings) + string(REGEX MATCH ".*#include.*s1.c.*#include.*s2.c.*#include.*s3.c.*#include.*s4.c.*" matched_code ${unitybuild_a_c_strings}) + if(NOT matched_code) + set(RunCMake_TEST_FAILED "Generated unity file doesn't include expected source files") + return() + endif() +endif() + +set(unitybuild_b_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_b_c.c") +if(NOT EXISTS "${unitybuild_b_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_b_c} does not exist.") + return() +endif() + + +set(unitybuild_a_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_a_cxx.cxx") +if(NOT EXISTS "${unitybuild_a_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_a_cxx} does not exist.") + return() +else() + #verify that the 4 cxx file are part of this grouping and therefore UNITY_BUILD_BATCH_SIZE + #was ignored + file(STRINGS ${unitybuild_a_cxx} unitybuild_a_cxx_strings) + string(REGEX MATCH ".*#include.*s1.cxx.*#include.*s2.cxx.*#include.*s3.cxx.*#include.*s4.cxx.*" matched_code ${unitybuild_a_cxx_strings}) + if(NOT matched_code) + set(RunCMake_TEST_FAILED "Generated unity file doesn't include expected source files") + return() + endif() +endif() + +set(unitybuild_b_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_b_cxx.cxx") +if(NOT EXISTS "${unitybuild_b_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_b_cxx} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group.cmake new file mode 100644 index 0000000..7bf3f4b --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_and_cxx_group.cmake @@ -0,0 +1,39 @@ +project(unitybuild_c_and_cxx C CXX) + +set(srcs f.c) +foreach(s RANGE 1 8) + set(src_c "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src_c}" " +int f(int);\n +int s${s}(void) { return f(${s}); }\n" + ) + + set(src_cxx "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cxx") + file(WRITE "${src_cxx}" " +extern \"C\" { \n + int f(int); \n +}\n + int s${s}(void) { return f(${s}); }\n" + ) + + list(APPEND srcs "${src_c}") + list(APPEND srcs "${src_cxx}") +endforeach() + + + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON + UNITY_BUILD_MODE GROUP + #UNITY_BUILD_BATCH_SIZE will be ignored + UNITY_BUILD_BATCH_SIZE 2) + +set_source_files_properties(s1.c s2.c s3.c s4.c + s1.cxx s2.cxx s3.cxx s4.cxx + PROPERTIES UNITY_GROUP "a" + ) +set_source_files_properties(s5.c s6.c s7.c s8.c + s5.cxx s6.cxx s7.cxx s8.cxx + PROPERTIES UNITY_GROUP "b" + ) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_batch-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_batch-check.cmake new file mode 100644 index 0000000..024286d --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_batch-check.cmake @@ -0,0 +1,5 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +if(NOT EXISTS "${unitybuild_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_batch.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_batch.cmake new file mode 100644 index 0000000..33873b6 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_batch.cmake @@ -0,0 +1,15 @@ +project(unitybuild_c C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES + UNITY_BUILD ON + UNITY_BUILD_MODE BATCH + ) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_group-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_group-check.cmake new file mode 100644 index 0000000..0b9ea15 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_group-check.cmake @@ -0,0 +1,11 @@ +set(unitybuild_a_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_a_c.c") +if(NOT EXISTS "${unitybuild_a_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_a_c} does not exist.") + return() +endif() + +set(unitybuild_b_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_b_c.c") +if(NOT EXISTS "${unitybuild_b_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_b_c} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_group.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_group.cmake new file mode 100644 index 0000000..1fa17f3 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_group.cmake @@ -0,0 +1,17 @@ +project(unitybuild_c C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON + UNITY_BUILD_MODE GROUP) + +set_source_files_properties(s1.c PROPERTIES UNITY_GROUP "a") +set_source_files_properties(s2.c PROPERTIES UNITY_GROUP "a") +set_source_files_properties(s3.c s4.c PROPERTIES UNITY_GROUP "b") diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build-check.cmake new file mode 100644 index 0000000..22d2fc6 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build-check.cmake @@ -0,0 +1,5 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +if(EXISTS "${unitybuild_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c} should not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build.cmake new file mode 100644 index 0000000..1185e9f --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build.cmake @@ -0,0 +1,10 @@ +project(unitybuild_c_no_unity_build C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group-check.cmake new file mode 100644 index 0000000..e344627 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group-check.cmake @@ -0,0 +1,5 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_a_c.c") +if(EXISTS "${unitybuild_c}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c} should not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group.cmake new file mode 100644 index 0000000..7b26dc1 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build_group.cmake @@ -0,0 +1,16 @@ +project(unitybuild_c_no_unity_build C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +#These should be ignored as UNITY_BUILD is off +set_target_properties(tgt PROPERTIES UNITY_BUILD_MODE GROUP) +set_source_files_properties(s1.c s2.c s3.c s4.c s5.c s6.c s7.c s8.c + PROPERTIES UNITY_GROUP "a" + ) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include-check.cmake new file mode 100644 index 0000000..e0935c7 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include-check.cmake @@ -0,0 +1,7 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +file(STRINGS ${unitybuild_c} unitybuild_c_strings) +string(REGEX MATCH "#define NOMINMAX.*#include.*s1.c.*#undef NOMINMAX" matched_code ${unitybuild_c_strings}) +if(NOT matched_code) + set(RunCMake_TEST_FAILED "Generated unity file doesn't include expected code before and after include") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include.cmake b/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include.cmake new file mode 100644 index 0000000..cc9cc28 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_code_before_and_after_include.cmake @@ -0,0 +1,13 @@ +project(unitybuild_code_before_and_after_include C) + +set(src "${CMAKE_CURRENT_BINARY_DIR}/s1.c") +file(WRITE "${src}" "int s1(void) { return 0; }\n") + +add_library(tgt SHARED ${src}) + +set_target_properties(tgt + PROPERTIES + UNITY_BUILD ON + UNITY_BUILD_CODE_BEFORE_INCLUDE "#define NOMINMAX" + UNITY_BUILD_CODE_AFTER_INCLUDE "#undef NOMINMAX" +) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_cxx-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_cxx-check.cmake new file mode 100644 index 0000000..9ef4c21 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_cxx-check.cmake @@ -0,0 +1,5 @@ +set(unitybuild_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_cxx.cxx") +if(NOT EXISTS "${unitybuild_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_cxx} does not exist.") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_cxx.cmake b/Tests/RunCMake/UnityBuild/unitybuild_cxx.cmake new file mode 100644 index 0000000..be800d7 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_cxx.cmake @@ -0,0 +1,12 @@ +project(unitybuild_cxx CXX) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cxx") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_cxx_group-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_cxx_group-check.cmake new file mode 100644 index 0000000..ecef3a3 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_cxx_group-check.cmake @@ -0,0 +1,27 @@ +set(unitybuild_a_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_a_cxx.cxx") +if(NOT EXISTS "${unitybuild_a_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_a_cxx} does not exist.") + return() +else() + #verify that odr2 is not part of this source set + file(STRINGS ${unitybuild_a_cxx} unitybuild_a_cxx_strings) + string(REGEX MATCH ".*#include.*odr2.cxx" matched_code ${unitybuild_a_cxx_strings}) + if(matched_code) + set(RunCMake_TEST_FAILED "Generated unity file includes un-expected ord2.cxx source file") + return() + endif() +endif() + +set(unitybuild_b_cxx "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_b_cxx.cxx") +if(NOT EXISTS "${unitybuild_b_cxx}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_b_cxx} does not exist.") + return() +else() + #verify that odr1 is not part of this source set + file(STRINGS ${unitybuild_b_cxx} unitybuild_b_cxx_strings) + string(REGEX MATCH ".*#include.*odr1.cxx" matched_code ${unitybuild_b_cxx_strings}) + if(matched_code) + set(RunCMake_TEST_FAILED "Generated unity file includes un-expected ord1.cxx source file") + return() + endif() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_cxx_group.cmake b/Tests/RunCMake/UnityBuild/unitybuild_cxx_group.cmake new file mode 100644 index 0000000..9804289 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_cxx_group.cmake @@ -0,0 +1,27 @@ +project(unitybuild_cxx CXX) + +set(srcs "") +foreach(s RANGE 1 4) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.cxx") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +foreach(s RANGE 1 2) + set(src "${CMAKE_CURRENT_BINARY_DIR}/odr${s}.cxx") + file(WRITE "${src}" "namespace odr { int s${s}(void) { return 0; } }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON + UNITY_BUILD_MODE GROUP + ) + +set_source_files_properties(s1.cxx s2.cxx odr1.cxx + PROPERTIES UNITY_GROUP "a" + ) +set_source_files_properties(s3.cxx s4.cxx odr2.cxx + PROPERTIES UNITY_GROUP "b" + ) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize-check.cmake new file mode 100644 index 0000000..9d39a70 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize-check.cmake @@ -0,0 +1,7 @@ +set(unitybuild_c0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +file(STRINGS ${unitybuild_c0} unitybuild_c_strings REGEX "/s[0-9]+.c\"$" ) +list(LENGTH unitybuild_c_strings number_of_includes) +if(NOT number_of_includes EQUAL 8) + set(RunCMake_TEST_FAILED "Generated unity doesn't include the expect number of files") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize.cmake b/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize.cmake new file mode 100644 index 0000000..60b9875 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize.cmake @@ -0,0 +1,15 @@ +project(unitybuild_default_batchsize C) + +set(srcs "") +foreach(s RANGE 1 10) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt + PROPERTIES + UNITY_BUILD ON +) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-result.txt b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-result.txt new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-stderr.txt b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-stderr.txt new file mode 100644 index 0000000..b1b17a0 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode-stderr.txt @@ -0,0 +1,5 @@ +^CMake Error in CMakeLists.txt: + Invalid UNITY_BUILD_MODE value of INVALID assigned to target tgt\. + Acceptable values are BATCH and GROUP\. +.* +CMake Generate step failed\. Build files cannot be regenerated correctly\.$ diff --git a/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode.cmake b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode.cmake new file mode 100644 index 0000000..0212200 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_invalid_mode.cmake @@ -0,0 +1,12 @@ +project(unitybuild_c C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON UNITY_BUILD_MODE INVALID) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_object_library.cmake b/Tests/RunCMake/UnityBuild/unitybuild_object_library.cmake new file mode 100644 index 0000000..b400517 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_object_library.cmake @@ -0,0 +1,13 @@ +project(unitybuild_object_library C) + +set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property + +add_library(lib OBJECT func.c) + +add_library(other-lib STATIC func.c) + +add_executable(main main.c) +target_link_libraries(main PRIVATE lib) + +enable_testing() +add_test(NAME main COMMAND main) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_order-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_order-check.cmake new file mode 100644 index 0000000..85e6587 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_order-check.cmake @@ -0,0 +1,7 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +file(STRINGS ${unitybuild_c} unitybuild_c_strings) +string(REGEX MATCH ".*#include.*s3.c.*#include.*s1.c.*#include.*s2.c.*" matched_code ${unitybuild_c_strings}) +if(NOT matched_code) + set(RunCMake_TEST_FAILED "Generated unity file doesn't include expected order of source files") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_order.cmake b/Tests/RunCMake/UnityBuild/unitybuild_order.cmake new file mode 100644 index 0000000..819603d --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_order.cmake @@ -0,0 +1,12 @@ +project(unitybuild_order C) + +set(srcs "") +foreach(s 3 1 2) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_runtest.cmake b/Tests/RunCMake/UnityBuild/unitybuild_runtest.cmake new file mode 100644 index 0000000..3589cc8 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_runtest.cmake @@ -0,0 +1,9 @@ +project(unitybuild_runtest C) + +set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property + +add_library(lib main.c func.c) +add_executable(main main.c func.c) + +enable_testing() +add_test(NAME main COMMAND main) diff --git a/Tests/RunCMake/UnityBuild/unitybuild_skip-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_skip-check.cmake new file mode 100644 index 0000000..e94ad72 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_skip-check.cmake @@ -0,0 +1,14 @@ +set(unitybuild_c "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0_c.c") +file(STRINGS ${unitybuild_c} unitybuild_c_strings) + +string(REGEX MATCH "\\/s[1-6].c" matched_files_1_6 ${unitybuild_c_strings}) +if(matched_files_1_6) + set(RunCMake_TEST_FAILED "Generated unity contains s1.c -> s6.c which should have been skipped") + return() +endif() + +string(REGEX MATCH "\\/s[7-8].c" matched_files_7_8 ${unitybuild_c_strings}) +if(NOT matched_files_7_8) + set(RunCMake_TEST_FAILED "Generated unity should have contained s7.c, s8.c!") + return() +endif() diff --git a/Tests/RunCMake/UnityBuild/unitybuild_skip.cmake b/Tests/RunCMake/UnityBuild/unitybuild_skip.cmake new file mode 100644 index 0000000..94e5aa3 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_skip.cmake @@ -0,0 +1,30 @@ +project(unitybuild_skip C) + +set(srcs "") +foreach(s RANGE 1 8) + set(src "${CMAKE_CURRENT_BINARY_DIR}/s${s}.c") + file(WRITE "${src}" "int s${s}(void) { return 0; }\n") + list(APPEND srcs "${src}") +endforeach() + +add_library(tgt SHARED ${srcs}) + +set_target_properties(tgt PROPERTIES UNITY_BUILD ON) + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s1.c + PROPERTIES HEADER_FILE_ONLY ON) + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s2.c + PROPERTIES SKIP_UNITY_BUILD_INCLUSION ON) + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s3.c + PROPERTIES COMPILE_OPTIONS "val") + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s4.c + PROPERTIES COMPILE_DEFINITIONS "val") + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s5.c + PROPERTIES COMPILE_FLAGS "val") + +set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/s6.c + PROPERTIES INCLUDE_DIRECTORIES "${CMAKE_CURRENT_BINARY_DIR}") |