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:
Ben Boeckel
2024-01-01 10:58:03 -05:00
parent b03e3c5251
commit 7fc2a83fe6
7 changed files with 68 additions and 0 deletions

View File

@@ -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)

View File

@@ -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)

View File

@@ -0,0 +1,10 @@
module;
#include "unity.h"
export module importable;
export int from_import()
{
return unity1() + unity2();
}

View File

@@ -0,0 +1,6 @@
import importable;
int main(int argc, char* argv[])
{
return from_import();
}

View File

@@ -0,0 +1,7 @@
#ifndef unity_h
#define unity_h
int unity1();
int unity2();
#endif

View File

@@ -0,0 +1,8 @@
#include "unity.h"
#define DETECT_UNITY
int unity1()
{
return 0;
}

View File

@@ -0,0 +1,10 @@
#include "unity.h"
#ifndef DETECT_UNITY
# error "Should have detected a unity build"
#endif
int unity2()
{
return 0;
}