Tests/CXXModules: add tests for exporting CXX_MODULE_STD
This commit is contained in:
parent
b8cc38f3a2
commit
85e1281e00
@ -243,6 +243,10 @@ if ("named" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
set(RunCMake_CXXModules_NO_TEST 1)
|
||||
run_cxx_module_test(import-std-no-std-property)
|
||||
unset(RunCMake_CXXModules_NO_TEST)
|
||||
run_cxx_module_test(import-std-export-no-std-build)
|
||||
set(RunCMake_CXXModules_INSTALL 1)
|
||||
run_cxx_module_test(import-std-export-no-std-install)
|
||||
unset(RunCMake_CXXModules_INSTALL)
|
||||
|
||||
if ("collation" IN_LIST CMake_TEST_MODULE_COMPILATION)
|
||||
run_cxx_module_test(import-std-not-in-export-build)
|
||||
|
@ -0,0 +1,56 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_export_no_std CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
set(CMAKE_NO_STD 1)
|
||||
|
||||
add_library(import_std_export_no_std)
|
||||
target_sources(import_std_export_no_std
|
||||
PRIVATE
|
||||
uses-std.cxx
|
||||
PUBLIC
|
||||
FILE_SET use_std TYPE CXX_MODULES FILES
|
||||
impl-uses-std.cxx)
|
||||
target_compile_features(import_std_export_no_std PUBLIC cxx_std_23)
|
||||
set_property(TARGET import_std_export_no_std
|
||||
PROPERTY
|
||||
CXX_MODULE_STD "$<BOOL:$<BUILD_LOCAL_INTERFACE:1>>")
|
||||
|
||||
add_executable(main
|
||||
main.cxx)
|
||||
target_link_libraries(main PRIVATE import_std_export_no_std)
|
||||
|
||||
install(TARGETS import_std_export_no_std
|
||||
EXPORT export
|
||||
ARCHIVE DESTINATION "lib"
|
||||
FILE_SET use_std DESTINATION "lib/cxx/miu")
|
||||
export(EXPORT export
|
||||
NAMESPACE CXXModules::
|
||||
FILE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-targets.cmake")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
|
||||
"include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_export_no_std-targets.cmake\")
|
||||
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
|
||||
")
|
||||
|
||||
add_test(NAME main COMMAND main)
|
||||
|
||||
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 import_std_export_no_std_build
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
"-Dexpected_dir=${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"-Dimport_std_export_no_std_DIR=${CMAKE_CURRENT_BINARY_DIR}"
|
||||
${generator}
|
||||
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
@ -0,0 +1,3 @@
|
||||
export module uses_std;
|
||||
|
||||
export int f();
|
@ -0,0 +1,6 @@
|
||||
import uses_std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return f();
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_library NONE)
|
||||
|
||||
find_package(import_std_export_no_std REQUIRED)
|
||||
|
||||
if (NOT TARGET CXXModules::import_std_export_no_std)
|
||||
message(FATAL_ERROR
|
||||
"Missing imported target")
|
||||
endif ()
|
||||
|
||||
function (check_property expected property)
|
||||
get_property(actual TARGET CXXModules::import_std_export_no_std
|
||||
PROPERTY "${property}")
|
||||
if (NOT DEFINED actual)
|
||||
if (NOT expected STREQUAL "<UNDEF>")
|
||||
message(SEND_ERROR
|
||||
"Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
|
||||
endif ()
|
||||
elseif (NOT actual STREQUAL expected)
|
||||
message(SEND_ERROR
|
||||
"Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
|
||||
check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
|
||||
check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
|
||||
check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
|
||||
check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
|
||||
check_property("$<BOOL:>" "CXX_MODULE_STD")
|
||||
|
||||
# Extract the export-dependent targets from the export file.
|
||||
file(STRINGS "${import_std_export_no_std_DIR}/import_std_export_no_std-targets.cmake" usage_dependent_targets
|
||||
REGEX "foreach._target ")
|
||||
# Rudimentary argument splitting.
|
||||
string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
|
||||
# Remove exported "target" names.
|
||||
list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
|
||||
# Strip quotes.
|
||||
string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
|
||||
|
||||
if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
|
||||
message(SEND_ERROR
|
||||
"The main export requires the '__CMAKE::CXX23' target")
|
||||
endif ()
|
@ -0,0 +1,8 @@
|
||||
module uses_std;
|
||||
|
||||
import std;
|
||||
|
||||
int f()
|
||||
{
|
||||
return 0;
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_import_std_export_no_std CXX)
|
||||
|
||||
include("${CMAKE_SOURCE_DIR}/../cxx-modules-rules.cmake")
|
||||
|
||||
add_library(import_std_export_no_std)
|
||||
target_sources(import_std_export_no_std
|
||||
PRIVATE
|
||||
uses-std.cxx
|
||||
PUBLIC
|
||||
FILE_SET use_std TYPE CXX_MODULES FILES
|
||||
impl-uses-std.cxx)
|
||||
target_compile_features(import_std_export_no_std PUBLIC cxx_std_23)
|
||||
set_property(TARGET import_std_export_no_std
|
||||
PROPERTY
|
||||
CXX_MODULE_STD "$<BOOL:$<BUILD_LOCAL_INTERFACE:1>>")
|
||||
|
||||
add_executable(main
|
||||
main.cxx)
|
||||
target_link_libraries(main PRIVATE import_std_export_no_std)
|
||||
|
||||
install(TARGETS import_std_export_no_std
|
||||
EXPORT export
|
||||
ARCHIVE DESTINATION "lib"
|
||||
FILE_SET use_std DESTINATION "lib/cxx/miu")
|
||||
install(
|
||||
EXPORT export
|
||||
NAMESPACE CXXModules::
|
||||
DESTINATION "lib/cmake/import_std_export_no_std"
|
||||
FILE "import_std_export_no_std-targets.cmake")
|
||||
file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
|
||||
"include(\"\${CMAKE_CURRENT_LIST_DIR}/import_std_export_no_std-targets.cmake\")
|
||||
set(\${CMAKE_FIND_PACKAGE_NAME}_FOUND 1)
|
||||
")
|
||||
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/import_std_export_no_std-config.cmake"
|
||||
DESTINATION "lib/cmake/import_std_export_no_std")
|
||||
|
||||
add_test(NAME main COMMAND main)
|
||||
|
||||
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 import_std_export_no_std_build
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}"
|
||||
"-Dexpected_dir=${CMAKE_INSTALL_PREFIX}/lib/cxx/miu"
|
||||
"-Dimport_std_export_no_std_DIR=${CMAKE_INSTALL_PREFIX}/lib/cmake/import_std_export_no_std"
|
||||
${generator}
|
||||
-S "${CMAKE_CURRENT_SOURCE_DIR}/test"
|
||||
-B "${CMAKE_CURRENT_BINARY_DIR}/test")
|
@ -0,0 +1,3 @@
|
||||
export module uses_std;
|
||||
|
||||
export int f();
|
@ -0,0 +1,6 @@
|
||||
import uses_std;
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
return f();
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
cmake_minimum_required(VERSION 3.29)
|
||||
project(cxx_modules_library NONE)
|
||||
|
||||
find_package(import_std_export_no_std REQUIRED)
|
||||
|
||||
if (NOT TARGET CXXModules::import_std_export_no_std)
|
||||
message(FATAL_ERROR
|
||||
"Missing imported target")
|
||||
endif ()
|
||||
|
||||
function (check_property expected property)
|
||||
get_property(actual TARGET CXXModules::import_std_export_no_std
|
||||
PROPERTY "${property}")
|
||||
if (NOT DEFINED actual)
|
||||
if (NOT expected STREQUAL "<UNDEF>")
|
||||
message(SEND_ERROR
|
||||
"Mismatch for ${property}:\n expected: ${expected}\n actual: NOT-DEFINED")
|
||||
endif ()
|
||||
elseif (NOT actual STREQUAL expected)
|
||||
message(SEND_ERROR
|
||||
"Mismatch for ${property}:\n expected: ${expected}\n actual: ${actual}")
|
||||
endif ()
|
||||
endfunction ()
|
||||
|
||||
check_property("<UNDEF>" "IMPORTED_CXX_MODULES_INCLUDE_DIRECTORIES")
|
||||
check_property("<UNDEF>" "IMPORTED_CXX_MODULES_COMPILE_DEFINITIONS")
|
||||
check_property("cxx_std_23" "IMPORTED_CXX_MODULES_COMPILE_FEATURES")
|
||||
check_property("" "IMPORTED_CXX_MODULES_LINK_LIBRARIES")
|
||||
check_property("<UNDEF>" "INTERFACE_LINK_LIBRARIES")
|
||||
check_property("$<BOOL:>" "CXX_MODULE_STD")
|
||||
|
||||
# Extract the export-dependent targets from the export file.
|
||||
file(STRINGS "${import_std_export_no_std_DIR}/import_std_export_no_std-targets.cmake" usage_dependent_targets
|
||||
REGEX "foreach._target ")
|
||||
# Rudimentary argument splitting.
|
||||
string(REPLACE " " ";" usage_dependent_targets "${usage_dependent_targets}")
|
||||
# Remove exported "target" names.
|
||||
list(FILTER usage_dependent_targets EXCLUDE REGEX "CXXModules::")
|
||||
# Strip quotes.
|
||||
string(REPLACE "\"" "" usage_dependent_targets "${usage_dependent_targets}")
|
||||
|
||||
if ("__CMAKE::CXX23" IN_LIST usage_dependent_targets)
|
||||
message(SEND_ERROR
|
||||
"The main export requires the '__CMAKE::CXX23' target")
|
||||
endif ()
|
@ -0,0 +1,9 @@
|
||||
module uses_std;
|
||||
import std;
|
||||
|
||||
int f()
|
||||
{
|
||||
std::string str = "hello!";
|
||||
std::cout << "program: " << str << std::endl;
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user