mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Improved the definition of options in CMake files, they can now be overriden by a parent CMakeLists.txt
This commit is contained in:
parent
c0af511ed1
commit
9d0a0fe3f2
@ -1,11 +1,17 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8)
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
|
||||||
|
# define a macro that helps defining an option
|
||||||
|
macro(sfml_set_option var default type docstring)
|
||||||
|
if(NOT ${var})
|
||||||
|
set(${var} ${default})
|
||||||
|
endif()
|
||||||
|
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
# set a default build type if none was provided
|
# set a default build type if none was provided
|
||||||
# this has to be done before the project() instruction!
|
# this has to be done before the project() instruction!
|
||||||
if(NOT CMAKE_BUILD_TYPE)
|
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
||||||
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# project name
|
# project name
|
||||||
project(SFML)
|
project(SFML)
|
||||||
@ -22,24 +28,24 @@ set(VERSION_PATCH 0)
|
|||||||
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
||||||
|
|
||||||
# add an option for choosing the build type (shared or static)
|
# add an option for choosing the build type (shared or static)
|
||||||
set(BUILD_SHARED_LIBS TRUE CACHE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
||||||
|
|
||||||
# add an option for building the examples
|
# add an option for building the examples
|
||||||
set(BUILD_EXAMPLES FALSE CACHE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
sfml_set_option(BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
||||||
|
|
||||||
# add an option for building the API documentation
|
# add an option for building the API documentation
|
||||||
set(BUILD_DOC FALSE CACHE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
sfml_set_option(BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
||||||
|
|
||||||
# Mac OS X specific options
|
# Mac OS X specific options
|
||||||
if(MACOSX)
|
if(MACOSX)
|
||||||
# add an option to build frameworks instead of dylibs (release only)
|
# add an option to build frameworks instead of dylibs (release only)
|
||||||
set(BUILD_FRAMEWORKS FALSE CACHE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
sfml_set_option(BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
||||||
|
|
||||||
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
||||||
set(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" CACHE STRING "Frameworks installation directory")
|
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
|
||||||
|
|
||||||
# add an option to automatically install Xcode 4 templates
|
# add an option to automatically install Xcode 4 templates
|
||||||
set(INSTALL_XCODE4_TEMPLATES FALSE CACHE BOOL "TRUE to automatically install the Xcode 4 templates, FALSE to do nothing about it")
|
sfml_set_option(INSTALL_XCODE4_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode 4 templates, FALSE to do nothing about it")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# define SFML_STATIC if the build type is not set to 'shared'
|
# define SFML_STATIC if the build type is not set to 'shared'
|
||||||
@ -54,7 +60,7 @@ endif()
|
|||||||
|
|
||||||
# define an option for choosing between static and dynamic C runtime (Windows only)
|
# define an option for choosing between static and dynamic C runtime (Windows only)
|
||||||
if(WINDOWS)
|
if(WINDOWS)
|
||||||
set(STATIC_STD_LIBS FALSE CACHE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
sfml_set_option(STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
||||||
|
|
||||||
# for VC++, we can apply it globally by modifying the compiler flags
|
# for VC++, we can apply it globally by modifying the compiler flags
|
||||||
if(COMPILER_MSVC AND STATIC_STD_LIBS)
|
if(COMPILER_MSVC AND STATIC_STD_LIBS)
|
||||||
@ -74,28 +80,22 @@ set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|||||||
# Setup Mac OS X stuff
|
# Setup Mac OS X stuff
|
||||||
if(MACOSX)
|
if(MACOSX)
|
||||||
# multi arch support - by default : i386 and x86_64
|
# multi arch support - by default : i386 and x86_64
|
||||||
if(NOT CMAKE_OSX_ARCHITECTURES)
|
sfml_set_option(CMAKE_OSX_ARCHITECTURES "i386;x86_64" STRING "Build architectures for OSX")
|
||||||
set(CMAKE_OSX_ARCHITECTURES "i386;x86_64" CACHE STRING "Build architectures for OSX" FORCE)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
# multi SDK support - by default we choose the older SDK available starting by 10.5 SDK
|
# multi SDK support - by default we choose the older SDK available starting by 10.5 SDK
|
||||||
if(NOT OSX_CONFIG_HAS_BEEN_RUN_BEFORE)
|
if(NOT OSX_CONFIG_HAS_BEEN_RUN_BEFORE)
|
||||||
if(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
|
if(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
|
||||||
# target 10.5 system
|
# target 10.5 system
|
||||||
set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.5.sdk"
|
sfml_set_option(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.5.sdk"
|
||||||
CACHE STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value."
|
STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value.")
|
||||||
FORCE)
|
sfml_set_option(CMAKE_OSX_DEPLOYMENT_TARGET "10.5"
|
||||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.5"
|
STRING "Minimum OS X version to target for deployment (at runtime); ewer APIs weak linked.")
|
||||||
CACHE STRING "Minimum OS X version to target for deployment (at runtime); ewer APIs weak linked."
|
|
||||||
FORCE)
|
|
||||||
elseif(EXISTS /Developer/SDKs/MacOSX10.6.sdk)
|
elseif(EXISTS /Developer/SDKs/MacOSX10.6.sdk)
|
||||||
# target 10.6 system
|
# target 10.6 system
|
||||||
set(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.6.sdk"
|
sfml_set_option(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.6.sdk"
|
||||||
CACHE STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value."
|
STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value.")
|
||||||
FORCE)
|
sfml_set_option(CMAKE_OSX_DEPLOYMENT_TARGET "10.6"
|
||||||
set(CMAKE_OSX_DEPLOYMENT_TARGET "10.6"
|
STRING "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked.")
|
||||||
CACHE STRING "Minimum OS X version to target for deployment (at runtime); newer APIs weak linked."
|
|
||||||
FORCE)
|
|
||||||
else()
|
else()
|
||||||
# use default SDK.
|
# use default SDK.
|
||||||
endif()
|
endif()
|
||||||
@ -115,13 +115,13 @@ if(MACOSX)
|
|||||||
if(BUILD_FRAMEWORKS)
|
if(BUILD_FRAMEWORKS)
|
||||||
# requirement #1
|
# requirement #1
|
||||||
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
||||||
message(WARNING "CMAKE_BUILD_TYPE should be \"Release\" when BUILD_FRAMEWORKS is TRUE")
|
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when BUILD_FRAMEWORKS is TRUE")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# requirement #2
|
# requirement #2
|
||||||
if(NOT BUILD_SHARED_LIBS)
|
if(NOT BUILD_SHARED_LIBS)
|
||||||
message(WARNING "BUILD_SHARED_LIBS should be TRUE when BUILD_FRAMEWORKS is TRUE")
|
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when BUILD_FRAMEWORKS is TRUE")
|
||||||
return()
|
return()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
Loading…
Reference in New Issue
Block a user