diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2024-01-01 15:58:03 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2024-01-05 10:03:29 (GMT) |
commit | 7fc2a83fe6a0dceb4fabfd6aac99a5cb2fa09ec5 (patch) | |
tree | 5c774f65dba5a2f714dd31717ada2fae79cf79df /Tests | |
parent | b03e3c5251596e597e81ad9cb0a435bf4675e6b7 (diff) | |
download | CMake-7fc2a83fe6a0dceb4fabfd6aac99a5cb2fa09ec5.zip CMake-7fc2a83fe6a0dceb4fabfd6aac99a5cb2fa09ec5.tar.gz CMake-7fc2a83fe6a0dceb4fabfd6aac99a5cb2fa09ec5.tar.bz2 |
Tests/CXXModules: add a test with unity build support
C++ module-using TUs cannot participate in unity builds. Add a test case
for this situation.
Diffstat (limited to 'Tests')
7 files changed, 68 insertions, 0 deletions
diff --git a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake index fcfa60a..cd7527a 100644 --- a/Tests/RunCMake/CXXModules/RunCMakeTest.cmake +++ b/Tests/RunCMake/CXXModules/RunCMakeTest.cmake @@ -171,6 +171,7 @@ run_cxx_module_test(scan-with-pch) if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION) run_cxx_module_test(simple) run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF) + run_cxx_module_test(unity-build) run_cxx_module_test(object-library) run_cxx_module_test(generated) run_cxx_module_test(deep-chain) diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/CMakeLists.txt b/Tests/RunCMake/CXXModules/examples/unity-build/CMakeLists.txt new file mode 100644 index 0000000..ce1751d --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.28) +project(cxx_modules_unity CXX) + +include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake") + +set(CMAKE_UNITY_BUILD 1) + +add_executable(unity) +target_sources(unity + PRIVATE + main.cxx + unity1.cxx + unity2.cxx + PRIVATE + FILE_SET CXX_MODULES + BASE_DIRS + "${CMAKE_CURRENT_SOURCE_DIR}" + FILES + importable.cxx) +target_compile_features(unity PUBLIC cxx_std_20) + +set_property(SOURCE unity1.cxx unity2.cxx + PROPERTY + CXX_SCAN_FOR_MODULES 0) + +add_test(NAME unity COMMAND unity) diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/importable.cxx b/Tests/RunCMake/CXXModules/examples/unity-build/importable.cxx new file mode 100644 index 0000000..148b033 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/importable.cxx @@ -0,0 +1,10 @@ +module; + +#include "unity.h" + +export module importable; + +export int from_import() +{ + return unity1() + unity2(); +} diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/main.cxx b/Tests/RunCMake/CXXModules/examples/unity-build/main.cxx new file mode 100644 index 0000000..feb38d2 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/main.cxx @@ -0,0 +1,6 @@ +import importable; + +int main(int argc, char* argv[]) +{ + return from_import(); +} diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/unity.h b/Tests/RunCMake/CXXModules/examples/unity-build/unity.h new file mode 100644 index 0000000..4a65a4b --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/unity.h @@ -0,0 +1,7 @@ +#ifndef unity_h +#define unity_h + +int unity1(); +int unity2(); + +#endif diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/unity1.cxx b/Tests/RunCMake/CXXModules/examples/unity-build/unity1.cxx new file mode 100644 index 0000000..fd1cbb3 --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/unity1.cxx @@ -0,0 +1,8 @@ +#include "unity.h" + +#define DETECT_UNITY + +int unity1() +{ + return 0; +} diff --git a/Tests/RunCMake/CXXModules/examples/unity-build/unity2.cxx b/Tests/RunCMake/CXXModules/examples/unity-build/unity2.cxx new file mode 100644 index 0000000..0f25cff --- /dev/null +++ b/Tests/RunCMake/CXXModules/examples/unity-build/unity2.cxx @@ -0,0 +1,10 @@ +#include "unity.h" + +#ifndef DETECT_UNITY +# error "Should have detected a unity build" +#endif + +int unity2() +{ + return 0; +} |