Browse Source

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.
Matthew Woehlke 8 months ago
parent
commit
647633e961

+ 1 - 0
Tests/RunCMake/CMakeLists.txt

@@ -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)

+ 3 - 0
Tests/RunCMake/CpsExportImport/CMakeLists.txt

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

+ 24 - 0
Tests/RunCMake/CpsExportImport/RunCMakeTest.cmake

@@ -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)

+ 12 - 0
Tests/RunCMake/CpsExportImport/TestExecutable.cmake

@@ -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)

+ 14 - 0
Tests/RunCMake/CpsExportImport/TestLibrary.cmake

@@ -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)

+ 13 - 0
Tests/RunCMake/CpsExportImport/app.c

@@ -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;
+}

+ 7 - 0
Tests/RunCMake/CpsExportImport/liba.c

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

+ 13 - 0
Tests/RunCMake/CpsExportImport/libb.c

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