cmake: Split SDL2-static and SDL2main into their own target exports This makes it so that the generated targets are not interdependent, which allows Linux distributions to split libraries into the appropriate subpackages as needed.
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
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3f6b98f..9686ecb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2754,7 +2754,6 @@ if(NOT WINDOWS_STORE)
add_library(SDL2::SDL2main ALIAS SDL2main)
target_include_directories(SDL2main BEFORE PRIVATE "${SDL2_BINARY_DIR}/include")
target_include_directories(SDL2main PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>)
- set(_INSTALL_LIBS "SDL2main")
if (NOT ANDROID)
set_target_properties(SDL2main PROPERTIES DEBUG_POSTFIX "${SDL_CMAKE_DEBUG_POSTFIX}")
endif()
@@ -2800,7 +2799,6 @@ if(SDL_SHARED)
endif()
set_target_properties(SDL2 PROPERTIES STATIC_LIBRARY_FLAGS "/NODEFAULTLIB")
endif()
- set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
target_link_libraries(SDL2 PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
target_include_directories(SDL2 BEFORE PRIVATE "${SDL2_BINARY_DIR}/include")
target_include_directories(SDL2 PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>;$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>;$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/SDL2>")
@@ -2832,7 +2830,6 @@ if(SDL_STATIC)
endif()
# TODO: Win32 platforms keep the same suffix .lib for import and static
# libraries - do we need to consider this?
- set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
target_link_libraries(SDL2-static PRIVATE ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
target_include_directories(SDL2-static BEFORE PRIVATE "${SDL2_BINARY_DIR}/include")
target_include_directories(SDL2-static PUBLIC "$<BUILD_INTERFACE:${SDL2_SOURCE_DIR}/include>" $<INSTALL_INTERFACE:include> $<INSTALL_INTERFACE:include/SDL2>)
@@ -2854,10 +2851,26 @@ if(SDL_TEST)
endif()
##### Installation targets #####
-install(TARGETS ${_INSTALL_LIBS} EXPORT SDL2Targets
- LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
- RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+if(SDL_SHARED)
+ install(TARGETS SDL2 EXPORT SDL2Targets
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+endif()
+
+if(NOT WINDOWS_STORE)
+ install(TARGETS SDL2main EXPORT SDL2mainTargets
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+endif()
+
+if(SDL_STATIC)
+ install(TARGETS SDL2-static EXPORT SDL2staticTargets
+ LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
+ RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+endif()
##### Export files #####
if (WINDOWS AND NOT MINGW)
@@ -2872,11 +2885,30 @@ write_basic_package_version_file("${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake"
COMPATIBILITY AnyNewerVersion
)
-install(EXPORT SDL2Targets
- FILE SDL2Targets.cmake
- NAMESPACE SDL2::
- DESTINATION ${PKG_PREFIX}
-)
+if(SDL_SHARED)
+ install(EXPORT SDL2Targets
+ FILE SDL2Targets.cmake
+ NAMESPACE SDL2::
+ DESTINATION ${PKG_PREFIX}
+ )
+endif()
+
+if(NOT WINDOWS_STORE)
+ install(EXPORT SDL2mainTargets
+ FILE SDL2mainTargets.cmake
+ NAMESPACE SDL2::
+ DESTINATION ${PKG_PREFIX}
+ )
+endif()
+
+if(SDL_STATIC)
+ install(EXPORT SDL2staticTargets
+ FILE SDL2staticTargets.cmake
+ NAMESPACE SDL2::
+ DESTINATION ${PKG_PREFIX}
+ )
+endif()
+
install(
FILES
${CMAKE_CURRENT_SOURCE_DIR}/SDL2Config.cmake
diff --git a/SDL2Config.cmake b/SDL2Config.cmake
index 7c31469..3e4ebe1 100644
--- a/SDL2Config.cmake
+++ b/SDL2Config.cmake
@@ -1,4 +1,12 @@
-include("${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
+if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")
+endif()
+if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2mainTargets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/SDL2mainTargets.cmake")
+endif()
+if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
+ include("${CMAKE_CURRENT_LIST_DIR}/SDL2staticTargets.cmake")
+endif()
# on static-only builds create an alias
if(NOT TARGET SDL2::SDL2 AND TARGET SDL2::SDL2-static)