summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <ben.boeckel@kitware.com>2023-07-25 18:26:53 (GMT)
committerBen Boeckel <ben.boeckel@kitware.com>2023-07-29 13:35:20 (GMT)
commit1c0963e9f2cd2b7a5ff5e02fc7c26e47232061f4 (patch)
tree6df29ec235c0992c7cb88b5fb29807d8e71dc06f
parent7b9378be43ac244baefb03bd7ab34ae882d3c1f1 (diff)
downloadCMake-1c0963e9f2cd2b7a5ff5e02fc7c26e47232061f4.zip
CMake-1c0963e9f2cd2b7a5ff5e02fc7c26e47232061f4.tar.gz
CMake-1c0963e9f2cd2b7a5ff5e02fc7c26e47232061f4.tar.bz2
Tests/RunCMake/property_init: add functions to make example targets
-rw-r--r--Tests/RunCMake/property_init/CMakeLists.txt5
-rw-r--r--Tests/RunCMake/property_init/library.c4
-rw-r--r--Tests/RunCMake/property_init/main.c4
-rw-r--r--Tests/RunCMake/property_init/util.cmake46
4 files changed, 58 insertions, 1 deletions
diff --git a/Tests/RunCMake/property_init/CMakeLists.txt b/Tests/RunCMake/property_init/CMakeLists.txt
index 9548deb..51883af 100644
--- a/Tests/RunCMake/property_init/CMakeLists.txt
+++ b/Tests/RunCMake/property_init/CMakeLists.txt
@@ -1,5 +1,8 @@
cmake_minimum_required(VERSION 3.12)
-project(${RunCMake_TEST} NONE)
+project(${RunCMake_TEST} C)
+
+set(main_sources main.c)
+set(library_sources library.c)
include(util.cmake)
diff --git a/Tests/RunCMake/property_init/library.c b/Tests/RunCMake/property_init/library.c
new file mode 100644
index 0000000..ad6a649
--- /dev/null
+++ b/Tests/RunCMake/property_init/library.c
@@ -0,0 +1,4 @@
+int foo(int arg)
+{
+ return arg;
+}
diff --git a/Tests/RunCMake/property_init/main.c b/Tests/RunCMake/property_init/main.c
new file mode 100644
index 0000000..14917b7
--- /dev/null
+++ b/Tests/RunCMake/property_init/main.c
@@ -0,0 +1,4 @@
+int main(int argc, char* argv[])
+{
+ return argc - 1;
+}
diff --git a/Tests/RunCMake/property_init/util.cmake b/Tests/RunCMake/property_init/util.cmake
index 41a200a..e98c2d5 100644
--- a/Tests/RunCMake/property_init/util.cmake
+++ b/Tests/RunCMake/property_init/util.cmake
@@ -1,3 +1,49 @@
+set(all_target_types
+ "EXECUTABLE"
+
+ "IMPORTED_EXECUTABLE"
+
+ "INTERFACE"
+ "MODULE"
+ "OBJECT"
+ "SHARED"
+ "STATIC"
+
+ "IMPORTED_INTERFACE"
+ "IMPORTED_MODULE"
+ "IMPORTED_OBJECT"
+ "IMPORTED_SHARED"
+ "IMPORTED_STATIC"
+
+ "CUSTOM")
+
+function (make_target name type)
+ if (type STREQUAL "EXECUTABLE")
+ add_executable("${name}")
+ target_sources("${name}" PRIVATE ${main_sources})
+ elseif (type STREQUAL "IMPORTED_EXECUTABLE")
+ add_executable("${name}" IMPORTED)
+ set_property(TARGET "${name}" PROPERTY IMPORTED_LOCATION "${CMAKE_COMMAND}")
+ elseif (type STREQUAL "CUSTOM")
+ add_custom_target("${name}" COMMAND "${CMAKE_EXECUTABLE}" -E echo "${name}")
+ elseif (type MATCHES "IMPORTED_")
+ string(REPLACE "IMPORTED_" "" type "${type}")
+ add_library("${name}" IMPORTED ${type})
+ if (NOT type STREQUAL "INTERFACE")
+ set_property(TARGET "${name}" PROPERTY IMPORTED_LOCATION "${default_library_location}")
+ endif ()
+ else ()
+ add_library("${name}" ${type})
+ target_sources("${name}" PRIVATE ${library_sources})
+ endif ()
+
+ if (type MATCHES "EXECUTABLE")
+ add_executable("alias::${name}" ALIAS "${name}")
+ elseif (NOT type STREQUAL "CUSTOM")
+ add_library("alias::${name}" ALIAS "${name}")
+ endif ()
+endfunction ()
+
function (check_property target property expected)
if (NOT TARGET "${target}")
message(SEND_ERROR