cmake: install SDL2::SDL2test when configuring with SDL2_TEST enabled
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1ac60d0..cb158c1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -346,6 +346,7 @@ if(EMSCRIPTEN)
set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF)
set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF)
set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF)
+ set(SDL_TEST_ENABLED_BY_DEFAULT OFF)
endif()
if(VITA OR PSP)
@@ -372,6 +373,10 @@ if (NOT DEFINED SDL_SHARED_ENABLED_BY_DEFAULT)
endif()
endif()
+if (NOT DEFINED SDL_TEST_ENABLED_BY_DEFAULT)
+ set(SDL_TEST_ENABLED_BY_DEFAULT ON)
+endif()
+
set(LONGESTOPTIONNAME 0) # set_option and friends will change this.
set(SDL_SUBSYSTEMS
@@ -469,9 +474,10 @@ set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors
set(SDL_SHARED ${SDL_SHARED_ENABLED_BY_DEFAULT} CACHE BOOL "Build a shared version of the library")
set(SDL_STATIC ${SDL_STATIC_ENABLED_BY_DEFAULT} CACHE BOOL "Build a static version of the library")
+set(SDL_TEST ${SDL_TEST_ENABLED_BY_DEFAULT} CACHE BOOL "Build the SDL2_test library")
dep_option(SDL_STATIC_PIC "Static version of the library should be built with Position Independent Code" OFF "SDL_STATIC" OFF)
-set_option(SDL_TEST "Build the test directory" OFF)
+dep_option(SDL_TESTS "Build the test directory" OFF SDL_TEST OFF)
set_option(SDL_INSTALL_TESTS "Install test-cases" OFF)
if(VITA)
@@ -2987,11 +2993,14 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DSDL_BUILD_MICRO_VERSION=${SDL_MICRO_VERSIO
##### Tests #####
if(SDL_TEST)
- include(CTest)
include_directories(BEFORE "${SDL2_BINARY_DIR}/include")
include_directories(AFTER "${SDL2_SOURCE_DIR}/include")
file(GLOB TEST_SOURCES ${SDL2_SOURCE_DIR}/src/test/*.c)
add_library(SDL2_test STATIC ${TEST_SOURCES})
+ add_library(SDL2::SDL2test ALIAS SDL2_test)
+ set_target_properties(SDL2_test PROPERTIES
+ EXPORT_NAME SDL2test)
+ target_include_directories(SDL2_test PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>)
endif()
##### Installation targets #####
@@ -3017,6 +3026,13 @@ if(NOT SDL2_DISABLE_INSTALL)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
endif()
+ if(SDL_TEST)
+ install(TARGETS SDL2_test EXPORT SDL2testTargets
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ endif()
+
##### Export files #####
if (WINDOWS AND NOT MINGW)
set(PKG_PREFIX "cmake")
@@ -3054,6 +3070,14 @@ if(NOT SDL2_DISABLE_INSTALL)
)
endif()
+ if(SDL_TEST)
+ install(EXPORT SDL2testTargets
+ FILE SDL2testTargets.cmake
+ NAMESPACE SDL2::
+ DESTINATION ${PKG_PREFIX}
+ )
+ endif()
+
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SDL2Config.cmake
@@ -3119,7 +3143,8 @@ endif()
##### Tests subproject (must appear after the install/uninstall targets) #####
-if(SDL_TEST)
+if(SDL_TESTS)
+ enable_testing()
add_subdirectory(test)
endif()
diff --git a/SDL2Config.cmake b/SDL2Config.cmake
index 3e4ebe1..39be60b 100644
--- a/SDL2Config.cmake
+++ b/SDL2Config.cmake
@@ -7,6 +7,9 @@ endif()
if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
endif()
+if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2testTargets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/SDL2testTargets.cmake")
+endif()
# on static-only builds create an alias
if(NOT TARGET SDL2::SDL2 AND TARGET SDL2::SDL2-static)
diff --git a/docs/README-cmake.md b/docs/README-cmake.md
index b13f2d2..03fd244 100644
--- a/docs/README-cmake.md
+++ b/docs/README-cmake.md
@@ -73,7 +73,7 @@ To use, set the following CMake variables when running CMake's configuration sta
- for iOS-Simulator, using the latest, installed SDK, and building SDL test apps (as .app bundles):
- `cmake ~/sdl -DSDL_TEST=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64`
+ `cmake ~/sdl -DSDL_TESTS=1 -DCMAKE_SYSTEM_NAME=iOS -DCMAKE_OSX_SYSROOT=iphonesimulator -DCMAKE_OSX_ARCHITECTURES=x86_64`
- for tvOS-Simulator, using the latest, installed SDK: