Merge topic 'exported-modules-with-headers' into release-3.29
2041f7c9bf
cmGeneratorTarget: add the original target as a COMPILE_ONLY link051c2110c8
Tests/CXXModules: test exporting modules which include headers Acked-by: Kitware Robot <kwrobot@kitware.com> Tested-by: buildbot <buildbot@kitware.com> Merge-request: !9469
This commit is contained in:
commit
c5d8fa3f2c
@ -8483,6 +8483,10 @@ bool cmGeneratorTarget::DiscoverSyntheticTargets(cmSyntheticTargetCache& cache,
|
||||
// generation.
|
||||
tgt->CopyImportedCxxModulesProperties(model);
|
||||
|
||||
tgt->AddLinkLibrary(*mf,
|
||||
cmStrCat("$<COMPILE_ONLY:", model->GetName(), '>'),
|
||||
GENERAL_LibraryType);
|
||||
|
||||
// Apply usage requirements to the target.
|
||||
usage.ApplyToTarget(tgt);
|
||||
|
||||
|
@ -267,6 +267,7 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
run_cxx_module_test(export-transitive-targets-build)
|
||||
run_cxx_module_test(export-transitive-modules1-build)
|
||||
run_cxx_module_test(export-transitive-modules-build export-transitive-modules-build "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-build-build" )
|
||||
run_cxx_module_test(export-with-headers-build)
|
||||
|
||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
||||
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
@ -287,6 +288,9 @@ if ("export_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
|
||||
set(test_suffix export-transitive-modules-build)
|
||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DTRANSITIVE_MODULES=1)
|
||||
|
||||
set(test_suffix export-with-headers-build)
|
||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-build" -DWITH_HEADERS=1)
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
@ -308,6 +312,7 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
run_cxx_module_test(export-transitive-targets-install)
|
||||
run_cxx_module_test(export-transitive-modules1-install)
|
||||
run_cxx_module_test(export-transitive-modules-install export-transitive-modules-install "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/export-transitive-modules1-install-install" )
|
||||
run_cxx_module_test(export-with-headers-install)
|
||||
|
||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION AND
|
||||
"bmionly" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
@ -329,6 +334,9 @@ if ("install_bmi" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
|
||||
set(test_suffix export-transitive-modules-install)
|
||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DTRANSITIVE_MODULES=1)
|
||||
|
||||
set(test_suffix export-with-headers-install)
|
||||
run_cxx_module_test(import-modules "import-modules-${test_suffix}" "-DCMAKE_PREFIX_PATH=${RunCMake_BINARY_DIR}/examples/${test_suffix}-install" -DWITH_HEADERS=1)
|
||||
set(RunCMake_CXXModules_INSTALL 1)
|
||||
endif ()
|
||||
endif ()
|
||||
|
@ -0,0 +1,49 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(export_with_headers CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
add_library(export_with_headers)
|
||||
target_sources(export_with_headers
|
||||
PUBLIC
|
||||
FILE_SET headers TYPE HEADERS
|
||||
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h"
|
||||
PUBLIC
|
||||
FILE_SET modules TYPE CXX_MODULES
|
||||
FILES
|
||||
importable.cxx)
|
||||
target_compile_features(export_with_headers PUBLIC cxx_std_20)
|
||||
|
||||
install(TARGETS export_with_headers
|
||||
EXPORT CXXModules
|
||||
FILE_SET headers
|
||||
FILE_SET modules DESTINATION ${CMAKE_INSTALL_LIBDIR}/miu)
|
||||
export(EXPORT CXXModules
|
||||
NAMESPACE CXXModules::
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-targets.cmake"
|
||||
CXX_MODULES_DIRECTORY "export_with_headers-cxx-modules")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake"
|
||||
"include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-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_with_headers_build
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
"-Dexport_with_headers_DIR=${CMAKE_CURRENT_BINARY_DIR}"
|
||||
${generator}
|
||||
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
@ -0,0 +1,14 @@
|
||||
module;
|
||||
|
||||
#include <subdir/header.h>
|
||||
|
||||
#ifndef from_subdir_header_h
|
||||
# error "Define from header found"
|
||||
#endif
|
||||
|
||||
export module importable;
|
||||
|
||||
export int from_import()
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define from_subdir_header_h 1
|
@ -0,0 +1,19 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(cxx_modules_library NONE)
|
||||
|
||||
find_package(export_with_headers REQUIRED)
|
||||
|
||||
if (NOT TARGET CXXModules::export_with_headers)
|
||||
message(FATAL_ERROR
|
||||
"Missing imported target")
|
||||
endif ()
|
||||
|
||||
get_property(iface_includes TARGET CXXModules::export_with_headers
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
set(include_dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
cmake_path(GET include_dir PARENT_PATH include_dir)
|
||||
string(APPEND include_dir "/include")
|
||||
if (NOT iface_includes STREQUAL "${include_dir};$<BUILD_INTERFACE:${include_dir}>")
|
||||
message(FATAL_ERROR
|
||||
"Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}")
|
||||
endif ()
|
@ -0,0 +1,51 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(export_with_headers CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
add_library(export_with_headers)
|
||||
target_sources(export_with_headers
|
||||
PUBLIC
|
||||
FILE_SET headers TYPE HEADERS
|
||||
BASE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
FILES
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/include/subdir/header.h"
|
||||
PUBLIC
|
||||
FILE_SET modules TYPE CXX_MODULES
|
||||
FILES
|
||||
importable.cxx)
|
||||
target_compile_features(export_with_headers PUBLIC cxx_std_20)
|
||||
|
||||
install(TARGETS export_with_headers
|
||||
EXPORT CXXModules
|
||||
FILE_SET headers
|
||||
FILE_SET modules DESTINATION lib/miu)
|
||||
install(EXPORT CXXModules
|
||||
NAMESPACE CXXModules::
|
||||
DESTINATION "lib/cmake/export_with_headers"
|
||||
FILE "export_with_headers-targets.cmake")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake"
|
||||
"include(\"\${CMAKE_CURRENT_LIST_DIR}/export_with_headers-targets.cmake\")
|
||||
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
|
||||
")
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/export_with_headers-config.cmake"
|
||||
DESTINATION "lib/cmake/export_with_headers")
|
||||
|
||||
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_with_headers_build
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
"-Dexport_with_headers_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/export_with_headers"
|
||||
${generator}
|
||||
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
@ -0,0 +1,14 @@
|
||||
module;
|
||||
|
||||
#include <subdir/header.h>
|
||||
|
||||
#ifndef from_subdir_header_h
|
||||
# error "Define from header found"
|
||||
#endif
|
||||
|
||||
export module importable;
|
||||
|
||||
export int from_import()
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
#define from_subdir_header_h 1
|
@ -0,0 +1,21 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(cxx_modules_library NONE)
|
||||
|
||||
find_package(export_with_headers REQUIRED)
|
||||
|
||||
if (NOT TARGET CXXModules::export_with_headers)
|
||||
message(FATAL_ERROR
|
||||
"Missing imported target")
|
||||
endif ()
|
||||
|
||||
get_property(iface_includes TARGET CXXModules::export_with_headers
|
||||
PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
|
||||
set(include_dir "${export_with_headers_DIR}")
|
||||
cmake_path(GET include_dir PARENT_PATH include_dir)
|
||||
cmake_path(GET include_dir PARENT_PATH include_dir)
|
||||
cmake_path(GET include_dir PARENT_PATH include_dir)
|
||||
string(APPEND include_dir "/include")
|
||||
if (NOT iface_includes STREQUAL "$<BUILD_INTERFACE:${include_dir}>")
|
||||
message(FATAL_ERROR
|
||||
"Incorrect include interface for CXXModules::export_with_headers:\n ${iface_includes}")
|
||||
endif ()
|
@ -15,6 +15,8 @@ elseif (TRANSITIVE_TARGETS)
|
||||
set(package_name "export_transitive_targets")
|
||||
elseif (TRANSITIVE_MODULES)
|
||||
set(package_name "export_transitive_modules")
|
||||
elseif (WITH_HEADERS)
|
||||
set(package_name "export_with_headers")
|
||||
else ()
|
||||
set(package_name "export_interfaces")
|
||||
endif ()
|
||||
|
Loading…
Reference in New Issue
Block a user