summaryrefslogtreecommitdiff
path: root/Tests/RunCMake/TargetArtifacts
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-02-24 15:00:32 -0500
committerBrad King <brad.king@kitware.com>2023-02-24 15:00:32 -0500
commit3cd34eb279df8419dd849360cc3b2f1133d3f281 (patch)
tree0bf97b1fe55051ac673159de45f450520d9457b1 /Tests/RunCMake/TargetArtifacts
parent35ca2d524befc71b840808cce4e0a773ef722b71 (diff)
downloadcmake-3cd34eb279df8419dd849360cc3b2f1133d3f281.tar.gz
Tests: Rename RunCMake.{ArtifactOutputDirs => TargetArtifacts}
Generalize the name so we can add other kinds of artifact checks.
Diffstat (limited to 'Tests/RunCMake/TargetArtifacts')
-rw-r--r--Tests/RunCMake/TargetArtifacts/CMakeLists.txt3
-rw-r--r--Tests/RunCMake/TargetArtifacts/OutputDirs.cmake27
-rw-r--r--Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake19
-rw-r--r--Tests/RunCMake/TargetArtifacts/check.cmake21
-rw-r--r--Tests/RunCMake/TargetArtifacts/lib.c4
-rw-r--r--Tests/RunCMake/TargetArtifacts/main.c4
6 files changed, 78 insertions, 0 deletions
diff --git a/Tests/RunCMake/TargetArtifacts/CMakeLists.txt b/Tests/RunCMake/TargetArtifacts/CMakeLists.txt
new file mode 100644
index 0000000000..ab1a20c7eb
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/CMakeLists.txt
@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 3.19)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)
diff --git a/Tests/RunCMake/TargetArtifacts/OutputDirs.cmake b/Tests/RunCMake/TargetArtifacts/OutputDirs.cmake
new file mode 100644
index 0000000000..d0accd7dea
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/OutputDirs.cmake
@@ -0,0 +1,27 @@
+enable_language(C)
+
+if(CMAKE_IMPORT_LIBRARY_SUFFIX)
+ set(expect_dll 1)
+else()
+ set(expect_dll 0)
+endif()
+
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/$<IF:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>,rtlib,rtbin>")
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/$<IF:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,SHARED_LIBRARY>,sharedlib,others>")
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/$<IF:$<STREQUAL:$<TARGET_PROPERTY:TYPE>,STATIC_LIBRARY>,staticlib,others>")
+
+add_executable(exe_tgt main.c)
+add_library(shared_tgt SHARED lib.c)
+add_library(static_tgt STATIC lib.c)
+
+add_custom_target(checkDirs ALL
+ COMMAND ${CMAKE_COMMAND}
+ -Dartifact_path=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>
+ -Dexe_name=$<TARGET_FILE_NAME:exe_tgt>
+ -Dshared_name=$<TARGET_FILE_NAME:shared_tgt>
+ -Dstatic_name=$<TARGET_FILE_NAME:static_tgt>
+ -Dexpect_dll=${expect_dll}
+ -P ${CMAKE_CURRENT_SOURCE_DIR}/check.cmake
+ )
+
+add_dependencies(checkDirs exe_tgt shared_tgt static_tgt)
diff --git a/Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake b/Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake
new file mode 100644
index 0000000000..54510b0332
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake
@@ -0,0 +1,19 @@
+include(RunCMake)
+
+function(run_cmake_and_verify_after_build case)
+ set(RunCMake_TEST_BINARY_DIR "${RunCMake_BINARY_DIR}/${case}-build")
+ file(REMOVE_RECURSE "${RunCMake_TEST_BINARY_DIR}")
+ file(MAKE_DIRECTORY "${RunCMake_TEST_BINARY_DIR}")
+ set(RunCMake_TEST_NO_CLEAN 1)
+ if(RunCMake_GENERATOR_IS_MULTI_CONFIG)
+ set(RunCMake_TEST_OPTIONS -DCMAKE_CONFIGURATION_TYPES=Debug)
+ else()
+ set(RunCMake_TEST_OPTIONS -DCMAKE_BUILD_TYPE=Debug)
+ endif()
+ run_cmake(${case})
+ run_cmake_command("${case}-build" ${CMAKE_COMMAND} --build .)
+ unset(RunCMake_TEST_NO_CLEAN)
+ unset(RunCMake_TEST_BINARY_DIR)
+endfunction()
+
+run_cmake_and_verify_after_build(OutputDirs)
diff --git a/Tests/RunCMake/TargetArtifacts/check.cmake b/Tests/RunCMake/TargetArtifacts/check.cmake
new file mode 100644
index 0000000000..ca37eba531
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/check.cmake
@@ -0,0 +1,21 @@
+set(expected ${artifact_path}/rtbin/${exe_name})
+if(NOT EXISTS "${expected}")
+ message(SEND_ERROR "executable artifact not created in the expected path:\n ${expected}")
+endif()
+
+set(expected ${artifact_path}/staticlib/${static_name})
+if(NOT EXISTS "${expected}")
+ message(SEND_ERROR "static artifact not created in the expected path:\n ${expected}")
+endif()
+
+if(expect_dll)
+ set(expected ${artifact_path}/rtlib/${shared_name})
+ if(NOT EXISTS "${expected}")
+ message(SEND_ERROR "dll artifact not created in the expected path:\n ${expected}")
+ endif()
+else()
+ set(expected ${artifact_path}/sharedlib/${shared_name})
+ if(NOT EXISTS "${expected}")
+ message(SEND_ERROR "shared artifact not created in the expected path:\n ${expected}")
+ endif()
+endif()
diff --git a/Tests/RunCMake/TargetArtifacts/lib.c b/Tests/RunCMake/TargetArtifacts/lib.c
new file mode 100644
index 0000000000..22373f1940
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/lib.c
@@ -0,0 +1,4 @@
+int func(void)
+{
+ return 0;
+}
diff --git a/Tests/RunCMake/TargetArtifacts/main.c b/Tests/RunCMake/TargetArtifacts/main.c
new file mode 100644
index 0000000000..8488f4e58f
--- /dev/null
+++ b/Tests/RunCMake/TargetArtifacts/main.c
@@ -0,0 +1,4 @@
+int main(void)
+{
+ return 0;
+}