mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-08 07:10:12 -05:00
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.
This commit is contained in:
@@ -171,6 +171,7 @@ run_cxx_module_test(scan-with-pch)
|
|||||||
if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||||
run_cxx_module_test(simple)
|
run_cxx_module_test(simple)
|
||||||
run_cxx_module_test(library library-static -DBUILD_SHARED_LIBS=OFF)
|
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(object-library)
|
||||||
run_cxx_module_test(generated)
|
run_cxx_module_test(generated)
|
||||||
run_cxx_module_test(deep-chain)
|
run_cxx_module_test(deep-chain)
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
export module importable;
|
||||||
|
|
||||||
|
export int from_import()
|
||||||
|
{
|
||||||
|
return unity1() + unity2();
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import importable;
|
||||||
|
|
||||||
|
int main(int argc, char* argv[])
|
||||||
|
{
|
||||||
|
return from_import();
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef unity_h
|
||||||
|
#define unity_h
|
||||||
|
|
||||||
|
int unity1();
|
||||||
|
int unity2();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
#define DETECT_UNITY
|
||||||
|
|
||||||
|
int unity1()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#include "unity.h"
|
||||||
|
|
||||||
|
#ifndef DETECT_UNITY
|
||||||
|
# error "Should have detected a unity build"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int unity2()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user