mirror of
https://github.com/Kitware/CMake.git
synced 2025-12-31 02:39:48 -06:00
Tests/CXXModules: add example for private modules between targets
Adapted from the example in issue #24652 by Ivan Garramona.
This commit is contained in:
@@ -155,6 +155,9 @@ endif ()
|
||||
# Tests which require collation work.
|
||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
run_cxx_module_test(public-req-private)
|
||||
set(RunCMake_CXXModules_NO_TEST 1)
|
||||
run_cxx_module_test(req-private-other-target)
|
||||
unset(RunCMake_CXXModules_NO_TEST)
|
||||
endif ()
|
||||
|
||||
# Tests which use named modules in shared libraries.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1 @@
|
||||
((Ninja generators)?(Unable to use module 'lib.priv' as it is 'PRIVATE' and therefore not accessible outside of its owning target.))
|
||||
@@ -0,0 +1,9 @@
|
||||
CMake Warning \(dev\) at CMakeLists.txt:7 \(target_sources\):
|
||||
CMake's C\+\+ module support is experimental. It is meant only for
|
||||
experimentation and feedback to CMake developers.
|
||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||
|
||||
CMake Warning \(dev\):
|
||||
C\+\+20 modules support via CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP is
|
||||
experimental. It is meant only for compiler developers to try.
|
||||
This warning is for project developers. Use -Wno-dev to suppress it.
|
||||
@@ -0,0 +1,16 @@
|
||||
cmake_minimum_required(VERSION 3.26)
|
||||
project(req_private_other_target CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
add_library(lib)
|
||||
target_sources(lib
|
||||
PUBLIC FILE_SET pub TYPE CXX_MODULES FILES lib.cxx
|
||||
PRIVATE FILE_SET priv TYPE CXX_MODULES FILES priv.cxx
|
||||
)
|
||||
target_compile_features(lib PUBLIC cxx_std_20)
|
||||
|
||||
add_executable(exe main.cxx)
|
||||
target_link_libraries(exe PRIVATE lib)
|
||||
|
||||
add_test(NAME exe COMMAND exe)
|
||||
@@ -0,0 +1 @@
|
||||
export module lib;
|
||||
@@ -0,0 +1,7 @@
|
||||
import lib;
|
||||
import lib.priv;
|
||||
|
||||
int main(int argc, char const* argv[])
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export module lib.priv;
|
||||
Reference in New Issue
Block a user