From 496337b3cfa9caaec12bd71690f6557a7dda99af Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 9 Aug 2017 19:03:10 -0700 Subject: [PATCH] Fixed bug 3651 - CMake build does not install CMake package configuration tschwinger@elitemail.org Most ironically, although autoconf/automake-based builds install (pretty half-assed) CMake package configuration files, they're missing in installations resulting from CMake-based builds entirely. A proper configuration file typically also loads target exports (implemented in patch 3572, also fixing this issue - see my comment on that issue for details). I believe it would be best to let the dinosaurs go extinct and redirect all build efforts to the CMake end for two reasons: 1. It potentially provides the best user experience, but you'd have to give it some love and ship with less quirky buildfiles. 2. It would force distros to build SDL via CMake and thus would ensure target exports are actually available everywhere. Various CMake patches I submitted today in summary (directly converted from the HG commits and `am`d onto a fork of a git mirror that happened to be on `tip`). https://github.com/tschw/SDL/commits/patched Fixing #2576 #3572, #3613, and this fresh ticket, which is almost entirely advertisement ;). These already do to make SDL much less of a quirky fella to have in your dependency tree... --- CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++++++----- Makefile.in | 2 +- SDL2Config.cmake | 1 + 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 SDL2Config.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 670fd462d..290cf985d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there") endif() -cmake_minimum_required(VERSION 2.8.5) +cmake_minimum_required(VERSION 2.8.11) project(SDL2 C) # !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property @@ -46,6 +46,12 @@ set(SDL_INTERFACE_AGE 1) set(SDL_BINARY_AGE 5) set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}") +# Set defaults preventing destination file conflicts +set(CMAKE_DEBUG_POSTFIX "d" + CACHE STRING "Name suffix for debug builds") + +mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX CMAKE_DEBUG_POSTFIX) + # Calculate a libtool-like version number math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}") math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}") @@ -1093,9 +1099,9 @@ elseif(WINDOWS) if(MSVC) # Prevent codegen that would use the VC runtime libraries. - add_definitions(/GS-) + set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-") if(NOT ARCH_64) - add_definitions(/arch:SSE) + set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE") endif() endif() @@ -1631,6 +1637,7 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}") # Always build SDLmain add_library(SDL2main STATIC ${SDLMAIN_SOURCES}) +target_include_directories(SDL2main PUBLIC $) set(_INSTALL_LIBS "SDL2main") if(SDL_SHARED) @@ -1654,12 +1661,19 @@ if(SDL_SHARED) endif() set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS}) target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) + target_include_directories(SDL2 PUBLIC $) endif() if(SDL_STATIC) set (BUILD_SHARED_LIBS FALSE) add_library(SDL2-static STATIC ${SOURCE_FILES}) - set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2") + if (NOT SDL_SHARED OR NOT WIN32) + set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2") + # Note: Apparently, OUTPUT_NAME must really be unique; even when + # CMAKE_IMPORT_LIBRARY_SUFFIX or the like are given. Otherwise + # the static build may race with the import lib and one will get + # clobbered, when the suffix is realized via subsequent rename. + endif() set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC}) if(MSVC AND NOT LIBC) set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB") @@ -1670,14 +1684,43 @@ if(SDL_STATIC) # libraries - do we need to consider this? set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS}) target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS}) + target_include_directories(SDL2-static PUBLIC $) endif() ##### Installation targets ##### -install(TARGETS ${_INSTALL_LIBS} +install(TARGETS ${_INSTALL_LIBS} EXPORT SDL2Targets LIBRARY DESTINATION "lib${LIB_SUFFIX}" ARCHIVE DESTINATION "lib${LIB_SUFFIX}" RUNTIME DESTINATION bin) +##### Export files ##### +if (APPLE) + set(PKG_PREFIX "SDL2.framework/Resources") +elseif (WINDOWS) + set(PKG_PREFIX "cmake") +else () + set(PKG_PREFIX "lib/cmake/SDL2") +endif () + +include(CMakePackageConfigHelpers) +write_basic_package_version_file("${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake" + VERSION ${SDL_VERSION} + COMPATIBILITY AnyNewerVersion +) + +install(EXPORT SDL2Targets + FILE SDL2Targets.cmake + NAMESPACE SDL2:: + DESTINATION ${PKG_PREFIX} +) +install( + FILES + ${CMAKE_SOURCE_DIR}/SDL2Config.cmake + ${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake + DESTINATION ${PKG_PREFIX} + COMPONENT Devel +) + file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h) file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h) foreach(_FNAME ${BIN_INCLUDE_FILES}) diff --git a/Makefile.in b/Makefile.in index d3445bf0f..74a84cacf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -44,7 +44,7 @@ SDLTEST_OBJECTS = @SDLTEST_OBJECTS@ WAYLAND_SCANNER = @WAYLAND_SCANNER@ -SRC_DIST = *.txt acinclude Android.mk autogen.sh android-project build-scripts cmake cmake_uninstall.cmake.in configure configure.in debian docs include Makefile.* sdl2-config.cmake.in sdl2-config.in sdl2.m4 sdl2.pc.in SDL2.spec.in src test VisualC.html VisualC VisualC-WinRT Xcode Xcode-iOS +SRC_DIST = *.txt acinclude Android.mk autogen.sh android-project build-scripts cmake cmake_uninstall.cmake.in configure configure.in debian docs include Makefile.* sdl2-config.cmake.in sdl2-config.in sdl2.m4 sdl2.pc.in SDL2.spec.in SDL2Config.cmake src test VisualC.html VisualC VisualC-WinRT Xcode Xcode-iOS GEN_DIST = SDL2.spec ifneq ($V,1) diff --git a/SDL2Config.cmake b/SDL2Config.cmake new file mode 100644 index 000000000..4a5f64602 --- /dev/null +++ b/SDL2Config.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/SDL2Targets.cmake")