diff options
author | Cristian Adam <cristian.adam@gmail.com> | 2019-07-29 17:33:55 (GMT) |
---|---|---|
committer | Cristian Adam <cristian.adam@gmail.com> | 2019-08-30 18:39:32 (GMT) |
commit | 1353802af366bd64ba8f730e6f93d4c416107d48 (patch) | |
tree | c721c50d768012fc631160aad6de8e51a19d029a /Tests | |
parent | 8dfeb5d278625c55be1cc82399d29c0305ee4438 (diff) | |
download | CMake-1353802af366bd64ba8f730e6f93d4c416107d48.zip CMake-1353802af366bd64ba8f730e6f93d4c416107d48.tar.gz CMake-1353802af366bd64ba8f730e6f93d4c416107d48.tar.bz2 |
Unity build: Add unit tests
Diffstat (limited to 'Tests')
30 files changed, 388 insertions, 0 deletions
diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 48eebcc..8fd5234 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -576,3 +576,4 @@ endif() add_RunCMake_test("CTestCommandExpandLists") add_RunCMake_test(PrecompileHeaders) +add_RunCMake_test("UnityBuild") 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..8e484d0 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/RunCMakeTest.cmake @@ -0,0 +1,23 @@ +include(RunCMake) + +run_cmake(unitybuild_c) +run_cmake(unitybuild_cxx) +run_cmake(unitybuild_c_and_cxx) +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_order) + +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) 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_batchsize-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_batchsize-check.cmake new file mode 100644 index 0000000..32bb8e7 --- /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") +set(unitybuild_c1 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_1.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..c980df0 --- /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") +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..32c2992 --- /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") +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") +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_no_unity_build-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_c_no_unity_build-check.cmake new file mode 100644 index 0000000..cb71ea3 --- /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") +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_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..8fcb18f --- /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") +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..89a037a --- /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") +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_default_batchsize-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_default_batchsize-check.cmake new file mode 100644 index 0000000..7dfc007 --- /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") +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_order-check.cmake b/Tests/RunCMake/UnityBuild/unitybuild_order-check.cmake new file mode 100644 index 0000000..533a89c --- /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") +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 oder 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..8816299 --- /dev/null +++ b/Tests/RunCMake/UnityBuild/unitybuild_runtest.cmake @@ -0,0 +1,8 @@ +project(unitybuild_runtest C) + +set(CMAKE_UNITY_BUILD ON) # This tests that the variable works in addition to the property + +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..fdd45bc --- /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") +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..74524ad --- /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 GENERATED 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}") diff --git a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake index 72154e7..dcdd177 100644 --- a/Tests/RunCMake/VS10Project/RunCMakeTest.cmake +++ b/Tests/RunCMake/VS10Project/RunCMakeTest.cmake @@ -34,3 +34,12 @@ endif() if(CMAKE_C_COMPILER_ID STREQUAL "MSVC" AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 19.20) run_cmake(VsSpectreMitigation) endif() + +# Visual Studio 2017 has toolset version 141 +string(REPLACE "v" "" generator_toolset "${RunCMake_GENERATOR_TOOLSET}") +if (RunCMake_GENERATOR MATCHES "Visual Studio 1[0-4] 201[0-5]" OR + (RunCMake_GENERATOR_TOOLSET AND generator_toolset VERSION_LESS "141")) + run_cmake(UnityBuildPre2017) +else() + run_cmake(UnityBuildNative) +endif() diff --git a/Tests/RunCMake/VS10Project/UnityBuildNative-check.cmake b/Tests/RunCMake/VS10Project/UnityBuildNative-check.cmake new file mode 100644 index 0000000..87f247d --- /dev/null +++ b/Tests/RunCMake/VS10Project/UnityBuildNative-check.cmake @@ -0,0 +1,45 @@ +set(unitybuild_c0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0.c") +if(NOT EXISTS "${unitybuild_c0}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c0} does not exist.") + return() +endif() + +set(tgt_project "${RunCMake_TEST_BINARY_DIR}/tgt.vcxproj") +if (NOT EXISTS "${tgt_project}") + set(RunCMake_TEST_FAILED "Generated project file ${tgt_project} doesn't exist.") + return() +endif() + +file(STRINGS ${tgt_project} tgt_projects_strings) + +foreach(line IN LISTS tgt_projects_strings) + if (line MATCHES "<EnableUnitySupport>true</EnableUnitySupport>") + set(have_unity_support ON) + endif() + + if (line MATCHES "<ClCompile Include=.*IncludeInUnityFile=\"false\" CustomUnityFile=\"true\"") + set(unity_source_line ${line}) + endif() + + if (line MATCHES "<ClCompile Include=.*IncludeInUnityFile=\"true\" CustomUnityFile=\"true\"") + list(APPEND sources_list ${line}) + endif() +endforeach() + +if (NOT have_unity_support) + set(RunCMake_TEST_FAILED "Generated project should include the <EnableUnitySupport> block.") + return() +endif() + +string(REPLACE "\\" "/" unity_source_line "${unity_source_line}") +string(FIND "${unity_source_line}" "CMakeFiles/tgt.dir/Unity/unity_0.c" unity_source_file_position) +if (unity_source_file_position EQUAL "-1") + set(RunCMake_TEST_FAILED "Generated project should include the generated unity source file.") + return() +endif() + +list(LENGTH sources_list number_of_sources) +if(NOT number_of_sources EQUAL 8) + set(RunCMake_TEST_FAILED "Generated project doesn't include the expect number of files.") + return() +endif() diff --git a/Tests/RunCMake/VS10Project/UnityBuildNative.cmake b/Tests/RunCMake/VS10Project/UnityBuildNative.cmake new file mode 100644 index 0000000..77a09cb --- /dev/null +++ b/Tests/RunCMake/VS10Project/UnityBuildNative.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/VS10Project/UnityBuildPre2017-check.cmake b/Tests/RunCMake/VS10Project/UnityBuildPre2017-check.cmake new file mode 100644 index 0000000..1c6bab8 --- /dev/null +++ b/Tests/RunCMake/VS10Project/UnityBuildPre2017-check.cmake @@ -0,0 +1,48 @@ +set(unitybuild_c0 "${RunCMake_TEST_BINARY_DIR}/CMakeFiles/tgt.dir/Unity/unity_0.c") +if(NOT EXISTS "${unitybuild_c0}") + set(RunCMake_TEST_FAILED "Generated unity source files ${unitybuild_c0} does not exist.") + return() +endif() + +set(tgt_project "${RunCMake_TEST_BINARY_DIR}/tgt.vcxproj") +if (NOT EXISTS "${tgt_project}") + set(RunCMake_TEST_FAILED "Generated project file ${tgt_project} doesn't exist.") + return() +endif() + +file(STRINGS ${tgt_project} tgt_projects_strings) + +foreach(line IN LISTS tgt_projects_strings) + if (line MATCHES "<ClCompile Include=.*/>") + set(unity_source_line ${line}) + endif() + + if (line MATCHES "<ClCompile Include=\"[^\"]*\">") + string(REGEX MATCH "<ClCompile Include=\"([^\"]*)\">" source_file ${line}) + list(APPEND sources_list ${source_file}) + endif() + + if (line MATCHES "<ExcludedFromBuild.*</ExcludedFromBuild>") + list(APPEND excluded_sources_list ${source_file}) + endif() +endforeach() + +string(REPLACE "\\" "/" unity_source_line ${unity_source_line}) +string(FIND "${unity_source_line}" "CMakeFiles/tgt.dir/Unity/unity_0.c" unity_source_file_position) +if (unity_source_file_position EQUAL "-1") + set(RunCMake_TEST_FAILED "Generated project should include the generated unity source file.") + return() +endif() + +list(LENGTH sources_list number_of_sources) +if(NOT number_of_sources EQUAL 8) + set(RunCMake_TEST_FAILED "Generated project doesn't include the expect number of files.") + return() +endif() + +# Exclusions for Debug|Release|MinSizeRel|RelWithDebInfo +list(LENGTH excluded_sources_list number_of_excluded_sources) +if(NOT number_of_excluded_sources EQUAL 32) + set(RunCMake_TEST_FAILED "Generated project doesn't exclude the source files for all configurations.") + return() +endif() diff --git a/Tests/RunCMake/VS10Project/UnityBuildPre2017.cmake b/Tests/RunCMake/VS10Project/UnityBuildPre2017.cmake new file mode 100644 index 0000000..77a09cb --- /dev/null +++ b/Tests/RunCMake/VS10Project/UnityBuildPre2017.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) |