CMakeLists.txt
changeset 11210 c92070a96da5
parent 11207 4ed2e42b7497
child 11212 52e36516928e
     1.1 --- a/CMakeLists.txt	Wed Aug 09 18:47:33 2017 -0700
     1.2 +++ b/CMakeLists.txt	Wed Aug 09 19:03:10 2017 -0700
     1.3 @@ -2,7 +2,7 @@
     1.4    message(FATAL_ERROR "Prevented in-tree built. Please create a build directory outside of the SDL source code and call cmake from there")
     1.5  endif()
     1.6  
     1.7 -cmake_minimum_required(VERSION 2.8.5)
     1.8 +cmake_minimum_required(VERSION 2.8.11)
     1.9  project(SDL2 C)
    1.10  
    1.11  # !!! FIXME: this should probably do "MACOSX_RPATH ON" as a target property
    1.12 @@ -46,6 +46,12 @@
    1.13  set(SDL_BINARY_AGE 5)
    1.14  set(SDL_VERSION "${SDL_MAJOR_VERSION}.${SDL_MINOR_VERSION}.${SDL_MICRO_VERSION}")
    1.15  
    1.16 +# Set defaults preventing destination file conflicts
    1.17 +set(CMAKE_DEBUG_POSTFIX "d"
    1.18 +    CACHE STRING "Name suffix for debug builds")
    1.19 +
    1.20 +mark_as_advanced(CMAKE_IMPORT_LIBRARY_SUFFIX CMAKE_DEBUG_POSTFIX)
    1.21 +
    1.22  # Calculate a libtool-like version number
    1.23  math(EXPR LT_CURRENT "${SDL_MICRO_VERSION} - ${SDL_INTERFACE_AGE}")
    1.24  math(EXPR LT_AGE "${SDL_BINARY_AGE} - ${SDL_INTERFACE_AGE}")
    1.25 @@ -1093,9 +1099,9 @@
    1.26  
    1.27    if(MSVC)
    1.28      # Prevent codegen that would use the VC runtime libraries.
    1.29 -    add_definitions(/GS-)
    1.30 +    set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-")
    1.31      if(NOT ARCH_64)
    1.32 -      add_definitions(/arch:SSE)
    1.33 +      set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE")
    1.34      endif()
    1.35    endif()
    1.36  
    1.37 @@ -1631,6 +1637,7 @@
    1.38  
    1.39  # Always build SDLmain
    1.40  add_library(SDL2main STATIC ${SDLMAIN_SOURCES})
    1.41 +target_include_directories(SDL2main PUBLIC $<INSTALL_INTERFACE:include>)
    1.42  set(_INSTALL_LIBS "SDL2main")
    1.43  
    1.44  if(SDL_SHARED)
    1.45 @@ -1654,12 +1661,19 @@
    1.46    endif()
    1.47    set(_INSTALL_LIBS "SDL2" ${_INSTALL_LIBS})
    1.48    target_link_libraries(SDL2 ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
    1.49 +  target_include_directories(SDL2 PUBLIC $<INSTALL_INTERFACE:include>)
    1.50  endif()
    1.51  
    1.52  if(SDL_STATIC)
    1.53    set (BUILD_SHARED_LIBS FALSE)
    1.54    add_library(SDL2-static STATIC ${SOURCE_FILES})
    1.55 -  set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
    1.56 +  if (NOT SDL_SHARED OR NOT WIN32)
    1.57 +    set_target_properties(SDL2-static PROPERTIES OUTPUT_NAME "SDL2")
    1.58 +    # Note: Apparently, OUTPUT_NAME must really be unique; even when
    1.59 +    # CMAKE_IMPORT_LIBRARY_SUFFIX or the like are given. Otherwise
    1.60 +    # the static build may race with the import lib and one will get
    1.61 +    # clobbered, when the suffix is realized via subsequent rename.
    1.62 +  endif()
    1.63    set_target_properties(SDL2-static PROPERTIES POSITION_INDEPENDENT_CODE ${SDL_STATIC_PIC})
    1.64    if(MSVC AND NOT LIBC)
    1.65      set_target_properties(SDL2-static PROPERTIES LINK_FLAGS_RELEASE "/NODEFAULTLIB")
    1.66 @@ -1670,14 +1684,43 @@
    1.67    # libraries - do we need to consider this?
    1.68    set(_INSTALL_LIBS "SDL2-static" ${_INSTALL_LIBS})
    1.69    target_link_libraries(SDL2-static ${EXTRA_LIBS} ${EXTRA_LDFLAGS})
    1.70 +  target_include_directories(SDL2-static PUBLIC $<INSTALL_INTERFACE:include>)
    1.71  endif()
    1.72  
    1.73  ##### Installation targets #####
    1.74 -install(TARGETS ${_INSTALL_LIBS}
    1.75 +install(TARGETS ${_INSTALL_LIBS} EXPORT SDL2Targets
    1.76    LIBRARY DESTINATION "lib${LIB_SUFFIX}"
    1.77    ARCHIVE DESTINATION "lib${LIB_SUFFIX}"
    1.78    RUNTIME DESTINATION bin)
    1.79  
    1.80 +##### Export files #####
    1.81 +if (APPLE)
    1.82 +  set(PKG_PREFIX "SDL2.framework/Resources")
    1.83 +elseif (WINDOWS)
    1.84 +  set(PKG_PREFIX "cmake")
    1.85 +else ()
    1.86 +  set(PKG_PREFIX "lib/cmake/SDL2")
    1.87 +endif ()
    1.88 +
    1.89 +include(CMakePackageConfigHelpers)
    1.90 +write_basic_package_version_file("${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake"
    1.91 +  VERSION ${SDL_VERSION}
    1.92 +  COMPATIBILITY AnyNewerVersion
    1.93 +)
    1.94 +
    1.95 +install(EXPORT SDL2Targets
    1.96 +  FILE SDL2Targets.cmake
    1.97 +  NAMESPACE SDL2::
    1.98 +  DESTINATION ${PKG_PREFIX}
    1.99 +)
   1.100 +install(
   1.101 +  FILES
   1.102 +    ${CMAKE_SOURCE_DIR}/SDL2Config.cmake
   1.103 +    ${CMAKE_BINARY_DIR}/SDL2ConfigVersion.cmake
   1.104 +  DESTINATION ${PKG_PREFIX}
   1.105 +  COMPONENT Devel
   1.106 +)
   1.107 +
   1.108  file(GLOB INCLUDE_FILES ${SDL2_SOURCE_DIR}/include/*.h)
   1.109  file(GLOB BIN_INCLUDE_FILES ${SDL2_BINARY_DIR}/include/*.h)
   1.110  foreach(_FNAME ${BIN_INCLUDE_FILES})