From 3cd34eb279df8419dd849360cc3b2f1133d3f281 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 24 Feb 2023 15:00:32 -0500 Subject: Tests: Rename RunCMake.{ArtifactOutputDirs => TargetArtifacts} Generalize the name so we can add other kinds of artifact checks. --- .../ArtifactOutputDirs/ArtifactOutputDirs.cmake | 27 ---------------------- Tests/RunCMake/ArtifactOutputDirs/CMakeLists.txt | 3 --- .../RunCMake/ArtifactOutputDirs/RunCMakeTest.cmake | 19 --------------- Tests/RunCMake/ArtifactOutputDirs/check.cmake | 21 ----------------- Tests/RunCMake/ArtifactOutputDirs/lib.c | 4 ---- Tests/RunCMake/ArtifactOutputDirs/main.c | 4 ---- Tests/RunCMake/CMakeLists.txt | 3 +-- Tests/RunCMake/TargetArtifacts/CMakeLists.txt | 3 +++ Tests/RunCMake/TargetArtifacts/OutputDirs.cmake | 27 ++++++++++++++++++++++ Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake | 19 +++++++++++++++ Tests/RunCMake/TargetArtifacts/check.cmake | 21 +++++++++++++++++ Tests/RunCMake/TargetArtifacts/lib.c | 4 ++++ Tests/RunCMake/TargetArtifacts/main.c | 4 ++++ 13 files changed, 79 insertions(+), 80 deletions(-) delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/ArtifactOutputDirs.cmake delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/CMakeLists.txt delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/RunCMakeTest.cmake delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/check.cmake delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/lib.c delete mode 100644 Tests/RunCMake/ArtifactOutputDirs/main.c create mode 100644 Tests/RunCMake/TargetArtifacts/CMakeLists.txt create mode 100644 Tests/RunCMake/TargetArtifacts/OutputDirs.cmake create mode 100644 Tests/RunCMake/TargetArtifacts/RunCMakeTest.cmake create mode 100644 Tests/RunCMake/TargetArtifacts/check.cmake create mode 100644 Tests/RunCMake/TargetArtifacts/lib.c create mode 100644 Tests/RunCMake/TargetArtifacts/main.c diff --git a/Tests/RunCMake/ArtifactOutputDirs/ArtifactOutputDirs.cmake b/Tests/RunCMake/ArtifactOutputDirs/ArtifactOutputDirs.cmake deleted file mode 100644 index d0accd7..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/ArtifactOutputDirs.cmake +++ /dev/null @@ -1,27 +0,0 @@ -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}/$/$,SHARED_LIBRARY>,rtlib,rtbin>") -set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$/$,SHARED_LIBRARY>,sharedlib,others>") -set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$/$,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}/$ - -Dexe_name=$ - -Dshared_name=$ - -Dstatic_name=$ - -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/ArtifactOutputDirs/CMakeLists.txt b/Tests/RunCMake/ArtifactOutputDirs/CMakeLists.txt deleted file mode 100644 index ab1a20c..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/CMakeLists.txt +++ /dev/null @@ -1,3 +0,0 @@ -cmake_minimum_required(VERSION 3.19) -project(${RunCMake_TEST} NONE) -include(${RunCMake_TEST}.cmake) diff --git a/Tests/RunCMake/ArtifactOutputDirs/RunCMakeTest.cmake b/Tests/RunCMake/ArtifactOutputDirs/RunCMakeTest.cmake deleted file mode 100644 index 1bf8438..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/RunCMakeTest.cmake +++ /dev/null @@ -1,19 +0,0 @@ -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(ArtifactOutputDirs) diff --git a/Tests/RunCMake/ArtifactOutputDirs/check.cmake b/Tests/RunCMake/ArtifactOutputDirs/check.cmake deleted file mode 100644 index ca37eba..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/check.cmake +++ /dev/null @@ -1,21 +0,0 @@ -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/ArtifactOutputDirs/lib.c b/Tests/RunCMake/ArtifactOutputDirs/lib.c deleted file mode 100644 index 22373f1..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/lib.c +++ /dev/null @@ -1,4 +0,0 @@ -int func(void) -{ - return 0; -} diff --git a/Tests/RunCMake/ArtifactOutputDirs/main.c b/Tests/RunCMake/ArtifactOutputDirs/main.c deleted file mode 100644 index 8488f4e..0000000 --- a/Tests/RunCMake/ArtifactOutputDirs/main.c +++ /dev/null @@ -1,4 +0,0 @@ -int main(void) -{ - return 0; -} diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index e372286..7ec9985 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -270,8 +270,6 @@ if(want_NoQt_test) add_RunCMake_test(AutogenNoQt TEST_DIR Autogen) endif() -add_RunCMake_test(ArtifactOutputDirs) - if(NOT DEFINED CMake_TEST_BuildDepends_GNU_AS AND (CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "LCC") AND CMAKE_GENERATOR MATCHES "^Ninja" @@ -396,6 +394,7 @@ if(UNIX AND CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG AND CMAKE_EXECUTABLE_FORMAT STRE endif() add_RunCMake_test(ScriptMode) add_RunCMake_test(Swift -DCMAKE_Swift_COMPILER=${CMAKE_Swift_COMPILER} -DCMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}) +add_RunCMake_test(TargetArtifacts) add_RunCMake_test(TargetObjects) add_RunCMake_test(TargetProperties) add_RunCMake_test(ToolchainFile) diff --git a/Tests/RunCMake/TargetArtifacts/CMakeLists.txt b/Tests/RunCMake/TargetArtifacts/CMakeLists.txt new file mode 100644 index 0000000..ab1a20c --- /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 0000000..d0accd7 --- /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}/$/$,SHARED_LIBRARY>,rtlib,rtbin>") +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$/$,SHARED_LIBRARY>,sharedlib,others>") +set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/$/$,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}/$ + -Dexe_name=$ + -Dshared_name=$ + -Dstatic_name=$ + -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 0000000..54510b0 --- /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 0000000..ca37eba --- /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 0000000..22373f1 --- /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 0000000..8488f4e --- /dev/null +++ b/Tests/RunCMake/TargetArtifacts/main.c @@ -0,0 +1,4 @@ +int main(void) +{ + return 0; +} -- cgit v0.12