2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 2.8)
|
|
|
|
|
|
2012-01-02 05:50:44 +08:00
|
|
|
|
# define a macro that helps defining an option
|
|
|
|
|
macro(sfml_set_option var default type docstring)
|
2012-01-02 14:47:13 +08:00
|
|
|
|
if(NOT DEFINED ${var})
|
2012-01-02 05:50:44 +08:00
|
|
|
|
set(${var} ${default})
|
|
|
|
|
endif()
|
|
|
|
|
set(${var} ${${var}} CACHE ${type} ${docstring} FORCE)
|
|
|
|
|
endmacro()
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# set a default build type if none was provided
|
|
|
|
|
# this has to be done before the project() instruction!
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)")
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# project name
|
|
|
|
|
project(SFML)
|
|
|
|
|
|
|
|
|
|
# include the configuration file
|
2011-08-07 21:33:42 +08:00
|
|
|
|
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.cmake)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# setup version numbers
|
|
|
|
|
set(VERSION_MAJOR 2)
|
|
|
|
|
set(VERSION_MINOR 0)
|
|
|
|
|
set(VERSION_PATCH 0)
|
|
|
|
|
|
|
|
|
|
# add the SFML header path
|
2011-08-07 21:33:42 +08:00
|
|
|
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# add an option for choosing the build type (shared or static)
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries")
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# add an option for building the examples
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them")
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# add an option for building the API documentation
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
|
2011-05-16 05:53:36 +08:00
|
|
|
|
|
|
|
|
|
# Mac OS X specific options
|
2011-12-15 02:54:44 +08:00
|
|
|
|
if(MACOSX)
|
|
|
|
|
# add an option to build frameworks instead of dylibs (release only)
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
|
|
|
|
|
# add an option to let the user specify a custom directory for frameworks installation (SFML, sndfile, ...)
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
|
|
|
|
|
# add an option to automatically install Xcode 4 templates
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(INSTALL_XCODE4_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode 4 templates, FALSE to do nothing about it")
|
2011-03-31 01:52:36 +08:00
|
|
|
|
endif()
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
2010-11-05 21:58:29 +08:00
|
|
|
|
# define SFML_STATIC if the build type is not set to 'shared'
|
|
|
|
|
if(NOT BUILD_SHARED_LIBS)
|
|
|
|
|
add_definitions(-DSFML_STATIC)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# remove SL security warnings with Visual C++
|
2011-12-29 04:39:23 +08:00
|
|
|
|
if(COMPILER_MSVC)
|
2010-08-19 23:59:24 +08:00
|
|
|
|
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
|
|
|
|
endif()
|
|
|
|
|
|
2011-05-16 05:53:36 +08:00
|
|
|
|
# define an option for choosing between static and dynamic C runtime (Windows only)
|
|
|
|
|
if(WINDOWS)
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs")
|
2011-05-16 05:53:36 +08:00
|
|
|
|
|
|
|
|
|
# for VC++, we can apply it globally by modifying the compiler flags
|
|
|
|
|
if(COMPILER_MSVC AND STATIC_STD_LIBS)
|
2011-03-27 06:24:09 +08:00
|
|
|
|
foreach(flag
|
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO)
|
|
|
|
|
if(${flag} MATCHES "/MD")
|
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag} "${${flag}}")
|
|
|
|
|
endif()
|
|
|
|
|
endforeach()
|
|
|
|
|
endif()
|
|
|
|
|
endif()
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
# disable the rpath stuff
|
2011-05-16 05:53:36 +08:00
|
|
|
|
set(CMAKE_SKIP_BUILD_RPATH TRUE)
|
|
|
|
|
|
2011-12-15 02:54:44 +08:00
|
|
|
|
# Setup Mac OS X stuff
|
|
|
|
|
if(MACOSX)
|
|
|
|
|
# multi arch support - by default : i386 and x86_64
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(CMAKE_OSX_ARCHITECTURES "i386;x86_64" STRING "Build architectures for OSX")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
|
|
|
|
|
# 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(EXISTS /Developer/SDKs/MacOSX10.5.sdk)
|
|
|
|
|
# target 10.5 system
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.5.sdk"
|
|
|
|
|
STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value.")
|
|
|
|
|
sfml_set_option(CMAKE_OSX_DEPLOYMENT_TARGET "10.5"
|
2012-01-03 19:35:49 +08:00
|
|
|
|
STRING "Minimum OS X version to target for deployment (at runtime), newer APIs weak linked.")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
elseif(EXISTS /Developer/SDKs/MacOSX10.6.sdk)
|
|
|
|
|
# target 10.6 system
|
2012-01-02 05:50:44 +08:00
|
|
|
|
sfml_set_option(CMAKE_OSX_SYSROOT "/Developer/SDKs/MacOSX10.6.sdk"
|
|
|
|
|
STRING "The product will be built against the headers and libraries located inside the indicated SDK. Set to empty string for default value.")
|
|
|
|
|
sfml_set_option(CMAKE_OSX_DEPLOYMENT_TARGET "10.6"
|
2012-01-03 19:35:49 +08:00
|
|
|
|
STRING "Minimum OS X version to target for deployment (at runtime), newer APIs weak linked.")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
else()
|
|
|
|
|
# use default SDK.
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# note : we use OSX_CONFIG_HAS_BEEN_RUN_BEFORE to be able to let the user set his/her custom settings
|
|
|
|
|
# so we don't always have to FORCE the value of CMAKE_OSX_DEPLOYMENT_TARGET and CMAKE_OSX_SYSROOT
|
|
|
|
|
set(OSX_CONFIG_HAS_BEEN_RUN_BEFORE TRUE
|
|
|
|
|
CACHE BOOL "Don't edit this value; you should instead empty your cache."
|
|
|
|
|
FORCE)
|
|
|
|
|
mark_as_advanced(OSX_CONFIG_HAS_BEEN_RUN_BEFORE)
|
2011-06-05 00:23:06 +08:00
|
|
|
|
endif()
|
2011-05-16 05:53:36 +08:00
|
|
|
|
|
2011-12-15 02:54:44 +08:00
|
|
|
|
# BUILD_FRAMEWORKS needs two things :
|
|
|
|
|
# first, it's available only for release
|
|
|
|
|
# (because cmake currently doesn't allow specifying a custom framework name so XXX-d is not possible)
|
|
|
|
|
# secondly, it works only with BUILD_SHARED_LIBS enabled
|
|
|
|
|
if(BUILD_FRAMEWORKS)
|
|
|
|
|
# requirement #1
|
|
|
|
|
if(NOT CMAKE_BUILD_TYPE STREQUAL "Release")
|
2012-01-02 05:50:44 +08:00
|
|
|
|
message(FATAL_ERROR "CMAKE_BUILD_TYPE should be \"Release\" when BUILD_FRAMEWORKS is TRUE")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
return()
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
# requirement #2
|
|
|
|
|
if(NOT BUILD_SHARED_LIBS)
|
2012-01-02 05:50:44 +08:00
|
|
|
|
message(FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when BUILD_FRAMEWORKS is TRUE")
|
2011-12-15 02:54:44 +08:00
|
|
|
|
return()
|
|
|
|
|
endif()
|
2011-05-16 05:53:36 +08:00
|
|
|
|
endif()
|
2011-03-31 01:52:36 +08:00
|
|
|
|
endif()
|
2010-08-19 23:59:24 +08:00
|
|
|
|
|
|
|
|
|
# add the subdirectories
|
|
|
|
|
add_subdirectory(src/SFML)
|
|
|
|
|
if(BUILD_EXAMPLES)
|
|
|
|
|
add_subdirectory(examples)
|
|
|
|
|
endif()
|
|
|
|
|
if(BUILD_DOC)
|
|
|
|
|
add_subdirectory(doc)
|
|
|
|
|
endif()
|
|
|
|
|
|
2011-12-15 02:54:44 +08:00
|
|
|
|
# setup the install rules
|
2011-08-20 18:14:55 +08:00
|
|
|
|
if(NOT BUILD_FRAMEWORKS)
|
|
|
|
|
install(DIRECTORY include
|
|
|
|
|
DESTINATION .
|
|
|
|
|
COMPONENT devel
|
2011-12-15 02:54:44 +08:00
|
|
|
|
PATTERN ".svn" EXCLUDE)
|
|
|
|
|
else()
|
|
|
|
|
# find only "root" headers
|
|
|
|
|
file(GLOB SFML_HEADERS RELATIVE ${PROJECT_SOURCE_DIR} "include/SFML/*")
|
|
|
|
|
|
|
|
|
|
# in fact we have to fool cmake to copy all the headers in subdirectories
|
|
|
|
|
# to do that we have to add the "root" headers to the PUBLIC_HEADER
|
|
|
|
|
# then we can run a post script to copy the remaining headers
|
|
|
|
|
|
|
|
|
|
# we need a dummy file in order to compile the framework
|
|
|
|
|
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp
|
|
|
|
|
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
|
|
|
|
|
|
|
|
|
set(SFML_SOURCES ${SFML_HEADERS})
|
|
|
|
|
list(APPEND SFML_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp)
|
|
|
|
|
|
|
|
|
|
# create SFML.framework
|
|
|
|
|
add_library(SFML ${SFML_SOURCES})
|
|
|
|
|
|
|
|
|
|
# edit target properties
|
|
|
|
|
set_target_properties(SFML PROPERTIES
|
|
|
|
|
FRAMEWORK TRUE
|
|
|
|
|
FRAMEWORK_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
|
|
|
MACOSX_FRAMEWORK_IDENTIFIER org.sfml-dev.SFML
|
|
|
|
|
MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
|
|
|
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
|
|
|
|
|
PUBLIC_HEADER "${SFML_HEADERS}")
|
|
|
|
|
|
|
|
|
|
# add the remaining headers
|
|
|
|
|
add_custom_command(TARGET SFML
|
|
|
|
|
POST_BUILD
|
|
|
|
|
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* SFML.framework/Versions/2.0.0/Headers)
|
|
|
|
|
|
|
|
|
|
# adapt install directory to allow distributing dylibs/frameworks in user’s frameworks/application bundle
|
|
|
|
|
# NOTE : it's not required to link agains SFML.framework
|
|
|
|
|
set_target_properties(SFML PROPERTIES
|
|
|
|
|
BUILD_WITH_INSTALL_RPATH 1
|
|
|
|
|
INSTALL_NAME_DIR "@executable_path/../Frameworks")
|
|
|
|
|
|
|
|
|
|
# install rule
|
|
|
|
|
install(TARGETS SFML
|
|
|
|
|
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}
|
|
|
|
|
COMPONENT devel)
|
|
|
|
|
endif()
|
|
|
|
|
|
|
|
|
|
install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
|
|
|
|
|
install(FILES license.txt DESTINATION ${INSTALL_MISC_DIR})
|
|
|
|
|
|
2010-08-19 23:59:24 +08:00
|
|
|
|
if(WINDOWS)
|
2011-03-29 00:20:27 +08:00
|
|
|
|
if(ARCH_32BITS)
|
|
|
|
|
install(FILES extlibs/bin/x86/libsndfile-1.dll DESTINATION bin)
|
|
|
|
|
install(FILES extlibs/bin/x86/openal32.dll DESTINATION bin)
|
|
|
|
|
else()
|
|
|
|
|
install(FILES extlibs/bin/x64/libsndfile-1.dll DESTINATION bin)
|
|
|
|
|
install(FILES extlibs/bin/x64/openal32.dll DESTINATION bin)
|
|
|
|
|
endif()
|
2011-03-27 06:24:09 +08:00
|
|
|
|
elseif(MACOSX)
|
2011-12-15 02:54:44 +08:00
|
|
|
|
install(DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
|
|
|
|
|
|
|
|
|
|
if(INSTALL_XCODE4_TEMPLATES)
|
|
|
|
|
install(DIRECTORY xcode/templates/SFML DESTINATION $ENV{HOME}/Library/Developer/Xcode/Templates)
|
2011-08-20 18:14:55 +08:00
|
|
|
|
endif()
|
2010-08-19 23:59:24 +08:00
|
|
|
|
endif()
|