Tests: Add CPS end-to-end test

Add a test that validates that we can export a package in CPS format and
import it again. This is fairly simplistic at the moment, but still
serves to validate some recent fixes that are not covered by more
targeted unit tests.
This commit is contained in:
Matthew Woehlke
2025-02-14 11:50:29 -05:00
committed by Brad King
parent 85721c4c56
commit 647633e961
8 changed files with 87 additions and 0 deletions

View File

@@ -396,6 +396,7 @@ set_property(TEST RunCMake.CompilerId APPEND PROPERTY LABELS "CUDA" "HIP" "ISPC"
add_RunCMake_test(CompilerTest ${CMake_TEST_LANG_VARS})
set_property(TEST RunCMake.CompilerTest APPEND PROPERTY LABELS "CUDA" "HIP" "ISPC" "Fortran")
add_RunCMake_test(Configure -DMSVC_IDE=${MSVC_IDE})
add_RunCMake_test(CpsExportImport)
add_RunCMake_test(DisallowedCommands)
if("${CMAKE_GENERATOR}" MATCHES "Unix Makefiles|Ninja")
add_RunCMake_test(ExportCompileCommands)

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 4.0)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,24 @@
include(RunCMake)
set(RunCMake_TEST_OPTIONS
-Wno-dev
"-DCMAKE_EXPERIMENTAL_EXPORT_PACKAGE_INFO:STRING=b80be207-778e-46ba-8080-b23bba22639e"
"-DCMAKE_EXPERIMENTAL_FIND_CPS_PACKAGES:STRING=e82e467b-f997-4464-8ace-b00808fff261"
)
function(build_project test)
set(RunCMake_TEST_NO_CLEAN FALSE)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/${test}-build)
if (NOT RunCMake_GENERATOR_IS_MULTI_CONFIG)
list(APPEND RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Release)
endif()
run_cmake(${test})
set(RunCMake_TEST_NO_CLEAN TRUE)
run_cmake_command(${test}-build ${CMAKE_COMMAND} --build . --config Release)
run_cmake_command(${test}-install ${CMAKE_COMMAND} --install . --config Release)
endfunction()
build_project(TestLibrary)
build_project(TestExecutable)

View File

@@ -0,0 +1,12 @@
project(TestLibrary C)
set(CMAKE_PREFIX_PATH "${CMAKE_BINARY_DIR}/../install")
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/../install")
find_package(libb REQUIRED COMPONENTS libb)
add_executable(app app.c)
target_link_libraries(app PUBLIC libb::libb)
install(TARGETS app DESTINATION bin)

View File

@@ -0,0 +1,14 @@
project(TestLibrary C)
set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/../install")
add_library(liba SHARED liba.c)
add_library(libb SHARED libb.c)
target_link_libraries(libb PUBLIC liba)
install(TARGETS liba EXPORT liba DESTINATION lib)
install(PACKAGE_INFO liba DESTINATION cps EXPORT liba)
install(TARGETS libb EXPORT libb DESTINATION lib)
install(PACKAGE_INFO libb DESTINATION cps EXPORT libb)

View File

@@ -0,0 +1,13 @@
#include <stdio.h>
extern
#ifdef _WIN32
__declspec(dllimport)
#endif
int ask(void);
int main(void)
{
printf("%i\n", ask());
return 0;
}

View File

@@ -0,0 +1,7 @@
#ifdef _WIN32
__declspec(dllexport)
#endif
int answer(void)
{
return 42;
}

View File

@@ -0,0 +1,13 @@
extern
#ifdef _WIN32
__declspec(dllimport)
#endif
int answer(void);
#ifdef _WIN32
__declspec(dllexport)
#endif
int ask(void)
{
return answer();
}