mirror of
https://github.com/Kitware/CMake.git
synced 2026-05-06 14:19:59 -05:00
Tests/CXXModules: add a test with transitive targets
This commit is contained in:
@@ -262,6 +262,7 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
|||||||
run_cxx_module_test(export-include-directories-build)
|
run_cxx_module_test(export-include-directories-build)
|
||||||
run_cxx_module_test(export-usage-build)
|
run_cxx_module_test(export-usage-build)
|
||||||
run_cxx_module_test(export-bmi-and-interface-build)
|
run_cxx_module_test(export-bmi-and-interface-build)
|
||||||
|
run_cxx_module_test(export-transitive-targets-build)
|
||||||
|
|
||||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
||||||
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||||
@@ -276,6 +277,9 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
|||||||
|
|
||||||
set(test_suffix export-bmi-and-interface-build)
|
set(test_suffix export-bmi-and-interface-build)
|
||||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_BMIS=1)
|
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_BMIS=1)
|
||||||
|
|
||||||
|
set(test_suffix export-transitive-targets-build)
|
||||||
|
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_TARGETS=1)
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
@@ -293,6 +297,7 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
|||||||
run_cxx_module_test(export-include-directories-install)
|
run_cxx_module_test(export-include-directories-install)
|
||||||
run_cxx_module_test(export-usage-install)
|
run_cxx_module_test(export-usage-install)
|
||||||
run_cxx_module_test(export-bmi-and-interface-install)
|
run_cxx_module_test(export-bmi-and-interface-install)
|
||||||
|
run_cxx_module_test(export-transitive-targets-install)
|
||||||
|
|
||||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
||||||
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||||
@@ -308,6 +313,9 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
|||||||
|
|
||||||
set(test_suffix export-bmi-and-interface-install)
|
set(test_suffix export-bmi-and-interface-install)
|
||||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_BMIS=1)
|
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_BMIS=1)
|
||||||
|
|
||||||
|
set(test_suffix export-transitive-targets-install)
|
||||||
|
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_TARGETS=1)
|
||||||
set(RunCMake_CXXModules_INSTALL 1)
|
set(RunCMake_CXXModules_INSTALL 1)
|
||||||
endif ()
|
endif ()
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.24...3.28)
|
||||||
|
project(cxx_modules_export_transitive_targets CXX)
|
||||||
|
|
||||||
|
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||||
|
|
||||||
|
add_library(usage_reqs INTERFACE
|
||||||
|
include/include.h
|
||||||
|
includes/includes.h)
|
||||||
|
target_compile_definitions(usage_reqs
|
||||||
|
INTERFACE
|
||||||
|
FROM_USAGE_REQS)
|
||||||
|
target_include_directories(usage_reqs
|
||||||
|
INTERFACE
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes>")
|
||||||
|
|
||||||
|
add_library(export_transitive_targets STATIC)
|
||||||
|
target_sources(export_transitive_targets
|
||||||
|
PRIVATE
|
||||||
|
forward.cxx
|
||||||
|
PRIVATE
|
||||||
|
FILE_SET modules_private TYPE CXX_MODULES
|
||||||
|
BASE_DIRS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
FILES
|
||||||
|
private.cxx
|
||||||
|
PUBLIC
|
||||||
|
FILE_SET modules TYPE CXX_MODULES
|
||||||
|
BASE_DIRS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
FILES
|
||||||
|
importable.cxx
|
||||||
|
subdir/importable.cxx
|
||||||
|
)
|
||||||
|
target_compile_features(export_transitive_targets PUBLIC cxx_std_20)
|
||||||
|
target_link_libraries(export_transitive_targets PRIVATE usage_reqs)
|
||||||
|
|
||||||
|
add_library(no_modules STATIC no_modules.cxx)
|
||||||
|
|
||||||
|
install(TARGETS usage_reqs export_transitive_targets no_modules
|
||||||
|
EXPORT CXXModules
|
||||||
|
FILE_SET modules DESTINATION "lib/cxx/miu")
|
||||||
|
export(EXPORT CXXModules
|
||||||
|
NAMESPACE CXXModules::
|
||||||
|
FILE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_targets-targets.cmake"
|
||||||
|
CXX_MODULES_DIRECTORY "export_transitive_targets-cxx-modules")
|
||||||
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_targets-config.cmake"
|
||||||
|
"include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_targets-targets.cmake\")
|
||||||
|
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
|
||||||
|
")
|
||||||
|
|
||||||
|
set(generator
|
||||||
|
-G "${CMAKE_GENERATOR}")
|
||||||
|
if (CMAKE_GENERATOR_TOOLSET)
|
||||||
|
list(APPEND generator
|
||||||
|
-T "${CMAKE_GENERATOR_TOOLSET}")
|
||||||
|
endif ()
|
||||||
|
if (CMAKE_GENERATOR_PLATFORM)
|
||||||
|
list(APPEND generator
|
||||||
|
-A "${CMAKE_GENERATOR_PLATFORM}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
add_test(NAME export_transitive_targets_build
|
||||||
|
COMMAND
|
||||||
|
"${CMAKE_COMMAND}"
|
||||||
|
"-Dexpected_source_dir=${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
"-Dexpected_binary_dir=${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
"-Dexport_transitive_targets_DIR=${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
|
${generator}
|
||||||
|
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||||
|
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import priv;
|
||||||
|
|
||||||
|
int forwarding()
|
||||||
|
{
|
||||||
|
return from_private();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include "include/include.h"
|
||||||
|
|
||||||
|
#ifndef include_h_included
|
||||||
|
# error "include define not found"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "includes/includes.h"
|
||||||
|
|
||||||
|
#ifndef includes_h_included
|
||||||
|
# error "includes define not found"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FROM_USAGE_REQS
|
||||||
|
# error "missing `FROM_USAGE_REQS` define"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
export module importable;
|
||||||
|
|
||||||
|
extern "C++" {
|
||||||
|
int forwarding();
|
||||||
|
}
|
||||||
|
|
||||||
|
export int from_import()
|
||||||
|
{
|
||||||
|
return forwarding();
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define include_h_included
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define includes_h_included
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
void no_modules()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export module priv;
|
||||||
|
|
||||||
|
export int from_private()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
export module subdir_importable;
|
||||||
|
|
||||||
|
export int from_subdir()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(cxx_modules_library NONE)
|
||||||
|
|
||||||
|
find_package(export_transitive_targets REQUIRED)
|
||||||
|
|
||||||
|
if (NOT TARGET CXXModules::export_transitive_targets)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Missing imported target")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
get_property(transitive_targets TARGET CXXModules::export_transitive_targets
|
||||||
|
PROPERTY IMPORTED_CXX_MODULES_LINK_LIBRARIES)
|
||||||
|
if (NOT transitive_targets STREQUAL "$<COMPILE_ONLY:CXXModules::usage_reqs>")
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Incorrect transitive link library in C++ module interface CXXModules::export_transitive_targets:\n ${transitive_targets}")
|
||||||
|
endif ()
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.24...3.28)
|
||||||
|
project(cxx_modules_export_transitive_targets CXX)
|
||||||
|
|
||||||
|
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||||
|
|
||||||
|
add_library(usage_reqs INTERFACE
|
||||||
|
include/include.h
|
||||||
|
includes/includes.h)
|
||||||
|
target_compile_definitions(usage_reqs
|
||||||
|
INTERFACE
|
||||||
|
FROM_USAGE_REQS)
|
||||||
|
target_include_directories(usage_reqs
|
||||||
|
INTERFACE
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
|
||||||
|
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/includes>"
|
||||||
|
"$<INSTALL_INTERFACE:include>")
|
||||||
|
|
||||||
|
add_library(export_transitive_targets STATIC)
|
||||||
|
target_sources(export_transitive_targets
|
||||||
|
PRIVATE
|
||||||
|
forward.cxx
|
||||||
|
PRIVATE
|
||||||
|
FILE_SET modules_private TYPE CXX_MODULES
|
||||||
|
BASE_DIRS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
FILES
|
||||||
|
private.cxx
|
||||||
|
PUBLIC
|
||||||
|
FILE_SET modules TYPE CXX_MODULES
|
||||||
|
BASE_DIRS
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||||
|
FILES
|
||||||
|
importable.cxx
|
||||||
|
subdir/importable.cxx
|
||||||
|
)
|
||||||
|
target_compile_features(export_transitive_targets PUBLIC cxx_std_20)
|
||||||
|
target_link_libraries(export_transitive_targets PRIVATE usage_reqs)
|
||||||
|
|
||||||
|
add_library(no_modules STATIC no_modules.cxx)
|
||||||
|
|
||||||
|
install(TARGETS usage_reqs export_transitive_targets no_modules
|
||||||
|
EXPORT CXXModules
|
||||||
|
FILE_SET modules DESTINATION "lib/cxx/miu"
|
||||||
|
INCLUDES DESTINATION "elsewhere")
|
||||||
|
install(DIRECTORY include
|
||||||
|
DESTINATION "include")
|
||||||
|
install(DIRECTORY includes
|
||||||
|
DESTINATION "elsewhere")
|
||||||
|
install(EXPORT CXXModules
|
||||||
|
NAMESPACE CXXModules::
|
||||||
|
DESTINATION "lib/cmake/export_transitive_targets"
|
||||||
|
FILE "export_transitive_targets-targets.cmake"
|
||||||
|
CXX_MODULES_DIRECTORY "export_transitive_targets-cxx-modules")
|
||||||
|
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_targets-config.cmake"
|
||||||
|
"include(\"\${CMAKE_CURRENT_LIST_DIR}/export_transitive_targets-targets.cmake\")
|
||||||
|
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
|
||||||
|
")
|
||||||
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_transitive_targets-config.cmake"
|
||||||
|
DESTINATION "lib/cmake/export_transitive_targets")
|
||||||
|
|
||||||
|
set(generator
|
||||||
|
-G "${CMAKE_GENERATOR}")
|
||||||
|
if (CMAKE_GENERATOR_TOOLSET)
|
||||||
|
list(APPEND generator
|
||||||
|
-T "${CMAKE_GENERATOR_TOOLSET}")
|
||||||
|
endif ()
|
||||||
|
if (CMAKE_GENERATOR_PLATFORM)
|
||||||
|
list(APPEND generator
|
||||||
|
-A "${CMAKE_GENERATOR_PLATFORM}")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
add_test(NAME export_transitive_targets_build
|
||||||
|
COMMAND
|
||||||
|
"${CMAKE_COMMAND}"
|
||||||
|
"-Dexpected_source_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu"
|
||||||
|
"-Dexpected_binary_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/bmi"
|
||||||
|
"-Dexport_transitive_targets_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_transitive_targets"
|
||||||
|
${generator}
|
||||||
|
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||||
|
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
import priv;
|
||||||
|
|
||||||
|
int forwarding()
|
||||||
|
{
|
||||||
|
return from_private();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
module;
|
||||||
|
|
||||||
|
#include "include/include.h"
|
||||||
|
|
||||||
|
#ifndef include_h_included
|
||||||
|
# error "include define not found"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "includes/includes.h"
|
||||||
|
|
||||||
|
#ifndef includes_h_included
|
||||||
|
# error "includes define not found"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef FROM_USAGE_REQS
|
||||||
|
# error "missing `FROM_USAGE_REQS` define"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
export module importable;
|
||||||
|
|
||||||
|
extern "C++" {
|
||||||
|
int forwarding();
|
||||||
|
}
|
||||||
|
|
||||||
|
export int from_import()
|
||||||
|
{
|
||||||
|
return forwarding();
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define include_h_included
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#define includes_h_included
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
void no_modules()
|
||||||
|
{
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export module priv;
|
||||||
|
|
||||||
|
export int from_private()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
export module subdir_importable;
|
||||||
|
|
||||||
|
export int from_subdir()
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
+16
@@ -0,0 +1,16 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.28)
|
||||||
|
project(cxx_modules_library NONE)
|
||||||
|
|
||||||
|
find_package(export_transitive_targets REQUIRED)
|
||||||
|
|
||||||
|
if (NOT TARGET CXXModules::export_transitive_targets)
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Missing imported target")
|
||||||
|
endif ()
|
||||||
|
|
||||||
|
get_property(transitive_targets TARGET CXXModules::export_transitive_targets
|
||||||
|
PROPERTY IMPORTED_CXX_MODULES_LINK_LIBRARIES)
|
||||||
|
if (NOT transitive_targets STREQUAL "$<COMPILE_ONLY:CXXModules::usage_reqs>")
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Incorrect transitive link library in C++ module interface CXXModules::export_transitive_targets:\n ${transitive_targets}")
|
||||||
|
endif ()
|
||||||
@@ -11,6 +11,8 @@ elseif (INCLUDE_PROPERTIES)
|
|||||||
set(package_name "export_include_directories")
|
set(package_name "export_include_directories")
|
||||||
elseif (FROM_NINJA)
|
elseif (FROM_NINJA)
|
||||||
set(package_name "export_from_ninja")
|
set(package_name "export_from_ninja")
|
||||||
|
elseif (TRANSITIVE_TARGETS)
|
||||||
|
set(package_name "export_transitive_targets")
|
||||||
else ()
|
else ()
|
||||||
set(package_name "export_interfaces")
|
set(package_name "export_interfaces")
|
||||||
endif ()
|
endif ()
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef FROM_USAGE_REQS
|
||||||
|
# error "compile definitions leaked from private module requirements"
|
||||||
|
#endif
|
||||||
|
|
||||||
import importable;
|
import importable;
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|||||||
Reference in New Issue
Block a user