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/RunCMake/VS10Project | |
parent | 8dfeb5d278625c55be1cc82399d29c0305ee4438 (diff) | |
download | CMake-1353802af366bd64ba8f730e6f93d4c416107d48.zip CMake-1353802af366bd64ba8f730e6f93d4c416107d48.tar.gz CMake-1353802af366bd64ba8f730e6f93d4c416107d48.tar.bz2 |
Unity build: Add unit tests
Diffstat (limited to 'Tests/RunCMake/VS10Project')
5 files changed, 126 insertions, 0 deletions
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) |