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 )
2013-07-21 15:03:27 +08:00
set ( VERSION_MINOR 1 )
2010-08-19 23:59:24 +08:00
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)
2013-10-12 21:26:46 +08:00
if ( NOT ( SFML_OS_IOS OR SFML_OS_ANDROID ) )
2013-09-12 05:15:08 +08:00
sfml_set_option ( BUILD_SHARED_LIBS TRUE BOOL "TRUE to build SFML as shared libraries, FALSE to build it as static libraries" )
2013-08-20 03:53:50 +08:00
else ( )
2013-10-12 21:26:46 +08:00
if ( SFML_OS_IOS )
2013-09-22 23:16:48 +08:00
set ( BUILD_SHARED_LIBS FALSE )
2013-10-12 21:26:46 +08:00
elseif ( SFML_OS_ANDROID )
2013-09-22 23:16:48 +08:00
set ( BUILD_SHARED_LIBS TRUE )
endif ( )
2013-08-20 03:53:50 +08:00
endif ( )
2010-08-19 23:59:24 +08:00
# add an option for building the examples
2013-10-12 21:26:46 +08:00
if ( NOT ( SFML_OS_IOS OR SFML_OS_ANDROID ) )
2013-09-12 05:15:08 +08:00
sfml_set_option ( SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them" )
else ( )
set ( SFML_BUILD_EXAMPLES FALSE )
endif ( )
2010-08-19 23:59:24 +08:00
# add an option for building the API documentation
2012-04-19 01:07:47 +08:00
sfml_set_option ( SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it" )
2014-04-16 00:44:55 +08:00
2013-08-20 03:53:50 +08:00
# add an option for choosing the OpenGL implementation
2014-04-21 03:32:05 +08:00
sfml_set_option ( SFML_OPENGL_ES ${ OPENGL_ES } BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation" )
2014-04-16 00:44:55 +08:00
2011-05-16 05:53:36 +08:00
# Mac OS X specific options
2013-10-09 14:01:10 +08:00
if ( SFML_OS_MACOSX )
2014-04-21 03:32:05 +08:00
# set default CMAKE_OSX_ARCHITECTURES value to x86_64
sfml_set_option ( CMAKE_OSX_ARCHITECTURES "x86_64" STRING "Build architectures for OS X" )
# set default CMAKE_OSX_DEPLOYMENT_TARGET value to 10.7
sfml_set_option ( CMAKE_OSX_DEPLOYMENT_TARGET "10.7" STRING "Minimum OS version to target for deployment (at runtime)" )
2011-12-15 02:54:44 +08:00
# add an option to build frameworks instead of dylibs (release only)
2012-04-19 01:07:47 +08:00
sfml_set_option ( SFML_BUILD_FRAMEWORKS FALSE BOOL "TRUE to build SFML as frameworks libraries (release only), FALSE to build according to BUILD_SHARED_LIBS" )
2014-04-13 18:42:14 +08:00
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-04-19 01:07:47 +08:00
sfml_set_option ( SFML_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
2013-09-22 23:16:48 +08:00
# Android options
2013-10-12 21:26:46 +08:00
if ( SFML_OS_ANDROID )
2013-09-22 23:16:48 +08:00
# force usage of the STL port
set ( ANDROID_USE_STLPORT TRUE )
2013-10-18 08:21:53 +08:00
# make sure there's the android library available
if ( ${ ANDROID_NATIVE_API_LEVEL } LESS 9 )
message ( FATAL_ERROR "API level must be equal or greater than 9" )
2013-09-22 23:16:48 +08:00
endif ( )
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
set ( CMAKE_INSTALL_PREFIX ${ ANDROID_NDK } /sources/sfml )
# we install libs in a subdirectory named after the ABI (lib/mips/*.so)
set ( LIB_SUFFIX "/${ANDROID_ABI}" )
2013-09-23 01:15:13 +08:00
# this is a workaround to compile sfml-activity without stlport_shared as dependency
# we save the original compilation command line to restore it later in Macro.cmake
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY_WITH_STLPORT ${ CMAKE_CXX_CREATE_SHARED_LIBRARY } )
set ( CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STLPORT "<CMAKE_CXX_COMPILER> <CMAKE_SHARED_LIBRARY_CXX_FLAGS> <LANGUAGE_COMPILE_FLAGS> <LINK_FLAGS> <CMAKE_SHARED_LIBRARY_CREATE_CXX_FLAGS> <SONAME_FLAG><TARGET_SONAME> -o <TARGET> <OBJECTS> <LINK_LIBRARIES>" )
2013-09-22 23:16:48 +08:00
endif ( )
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++
2013-10-09 14:01:10 +08:00
if ( SFML_COMPILER_MSVC )
2010-08-19 23:59:24 +08:00
add_definitions ( -D_CRT_SECURE_NO_DEPRECATE )
endif ( )
2013-08-20 03:53:50 +08:00
# define SFML_OPENGL_ES if needed
if ( SFML_OPENGL_ES )
add_definitions ( -DSFML_OPENGL_ES )
2013-12-19 07:59:09 +08:00
add_definitions ( -DGL_GLEXT_PROTOTYPES )
2013-08-20 03:53:50 +08:00
endif ( )
2011-05-16 05:53:36 +08:00
# define an option for choosing between static and dynamic C runtime (Windows only)
2013-10-09 14:01:10 +08:00
if ( SFML_OS_WINDOWS )
2012-04-19 01:07:47 +08:00
sfml_set_option ( SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs" )
2012-09-17 02:12:42 +08:00
# the following combination of flags is not valid
if ( BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS )
message ( FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together" )
endif ( )
2011-05-16 05:53:36 +08:00
# for VC++, we can apply it globally by modifying the compiler flags
2013-10-09 14:01:10 +08:00
if ( SFML_COMPILER_MSVC AND SFML_USE_STATIC_STD_LIBS )
2011-03-27 06:24:09 +08:00
foreach ( flag
C M A K E _ C X X _ F L A G S C M A K E _ C X X _ F L A G S _ D E B U G C M A K E _ C X X _ F L A G S _ R E L E A S E
C M A K E _ C X X _ F L A G S _ M I N S I Z E R E L C M A K E _ C X X _ F L A G S _ R E L W I T H D E B I N F O )
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 )
2013-02-26 02:17:46 +08:00
# setup Mac OS X stuff
2013-10-09 14:01:10 +08:00
if ( SFML_OS_MACOSX )
2013-01-19 18:23:12 +08:00
# SFML_BUILD_FRAMEWORKS needs two things :
2011-12-15 02:54:44 +08:00
# 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
2012-04-19 01:07:47 +08:00
if ( SFML_BUILD_FRAMEWORKS )
2011-12-15 02:54:44 +08:00
# requirement #1
if ( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
2012-04-19 01:07:47 +08:00
message ( FATAL_ERROR "CMAKE_BUILD_TYPE should be \" Release\ " when SFML_BUILD_FRAMEWORKS is TRUE" )
2011-12-15 02:54:44 +08:00
return ( )
endif ( )
# requirement #2
if ( NOT BUILD_SHARED_LIBS )
2012-04-19 01:07:47 +08:00
message ( FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE" )
2011-12-15 02:54:44 +08:00
return ( )
endif ( )
2011-05-16 05:53:36 +08:00
endif ( )
2014-04-13 18:42:14 +08:00
# Objective-C ARC requires a 64 bit runtime.
if ( NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64" )
2014-04-21 03:45:22 +08:00
message ( FATAL_ERROR "CMAKE_OSX_ARCHITECTURES should be 'x86_64'; SFML doesn't support 32 bit on Mac OS X." )
2014-04-13 18:42:14 +08:00
return ( )
endif ( )
2014-04-16 00:44:55 +08:00
# make sure CMAKE_OSX_DEPLOYMENT_TARGET is >= 10.7
if ( CMAKE_OSX_DEPLOYMENT_TARGET VERSION_LESS "10.7" )
message ( FATAL_ERROR "CMAKE_OSX_DEPLOYMENT_TARGET (${CMAKE_OSX_DEPLOYMENT_TARGET}) should be 10.7 or better" )
return ( )
endif ( )
2011-03-31 01:52:36 +08:00
endif ( )
2010-08-19 23:59:24 +08:00
2013-10-09 14:01:10 +08:00
if ( SFML_OS_LINUX OR SFML_OS_FREEBSD )
2014-04-25 21:52:55 +08:00
set ( PKGCONFIG_DIR lib ${ LIB_SUFFIX } /pkgconfig )
if ( SFML_OS_FREEBSD )
set ( PKGCONFIG_DIR libdata/pkgconfig )
endif ( )
2012-01-11 05:08:20 +08:00
if ( BUILD_SHARED_LIBS )
2013-08-05 02:40:10 +08:00
sfml_set_option ( SFML_INSTALL_PKGCONFIG_FILES FALSE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML" )
2012-04-19 01:07:47 +08:00
if ( SFML_INSTALL_PKGCONFIG_FILES )
2012-01-11 05:08:20 +08:00
foreach ( sfml_module IN ITEMS all system window graphics audio network )
CONFIGURE_FILE (
" t o o l s / p k g - c o n f i g / s f m l - $ { s f m l _ m o d u l e } . p c . i n "
" t o o l s / p k g - c o n f i g / s f m l - $ { s f m l _ m o d u l e } . p c "
@ O N L Y )
2014-04-21 03:32:05 +08:00
INSTALL ( FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
2014-04-25 21:52:55 +08:00
D E S T I N A T I O N " $ { C M A K E _ I N S T A L L _ P R E F I X } / $ { P K G C O N F I G _ D I R } " )
2012-01-11 05:08:20 +08:00
endforeach ( )
endif ( )
else ( )
2012-04-19 01:07:47 +08:00
if ( SFML_INSTALL_PKGCONFIG_FILES )
message ( WARNING "No pkg-config files are provided for the static SFML libraries (SFML_INSTALL_PKGCONFIG_FILES will be ignored)." )
2012-01-11 05:08:20 +08:00
endif ( )
endif ( )
endif ( )
2013-02-26 02:17:46 +08:00
# enable project folders
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
set_property ( GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake" )
2010-08-19 23:59:24 +08:00
# add the subdirectories
add_subdirectory ( src/SFML )
2012-04-19 01:07:47 +08:00
if ( SFML_BUILD_EXAMPLES )
2010-08-19 23:59:24 +08:00
add_subdirectory ( examples )
endif ( )
2012-04-19 01:07:47 +08:00
if ( SFML_BUILD_DOC )
2010-08-19 23:59:24 +08:00
add_subdirectory ( doc )
endif ( )
2011-12-15 02:54:44 +08:00
# setup the install rules
2012-04-19 01:07:47 +08:00
if ( NOT SFML_BUILD_FRAMEWORKS )
2011-08-20 18:14:55 +08:00
install ( DIRECTORY include
D E S T I N A T I O N .
C O M P O N E N T d e v e l
2013-09-13 22:09:22 +08:00
F I L E S _ M A T C H I N G P A T T E R N " * . h p p " P A T T E R N " * . i n l " )
2011-12-15 02:54:44 +08:00
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
C O M M A N D t o u c h $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / d u m m y . c p p )
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
2014-04-13 18:42:14 +08:00
set_target_properties ( SFML PROPERTIES
2011-12-15 02:54:44 +08:00
F R A M E W O R K T R U E
F R A M E W O R K _ V E R S I O N $ { V E R S I O N _ M A J O R } . $ { V E R S I O N _ M I N O R } . $ { V E R S I O N _ P A T C H }
M A C O S X _ F R A M E W O R K _ I D E N T I F I E R o r g . s f m l - d e v . S F M L
M A C O S X _ F R A M E W O R K _ S H O R T _ V E R S I O N _ S T R I N G $ { V E R S I O N _ M A J O R } . $ { V E R S I O N _ M I N O R } . $ { V E R S I O N _ P A T C H }
M A C O S X _ F R A M E W O R K _ B U N D L E _ V E R S I O N $ { V E R S I O N _ M A J O R } . $ { V E R S I O N _ M I N O R } . $ { V E R S I O N _ P A T C H }
P U B L I C _ H E A D E R " $ { S F M L _ H E A D E R S } " )
# add the remaining headers
2014-04-13 18:42:14 +08:00
add_custom_command ( TARGET SFML
2011-12-15 02:54:44 +08:00
P O S T _ B U I L D
2014-05-13 06:21:39 +08:00
C O M M A N D c p - r $ { P R O J E C T _ S O U R C E _ D I R } / i n c l u d e / S F M L / * $ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s )
2014-04-21 03:32:05 +08:00
2013-08-26 02:39:55 +08:00
# adapt install directory to allow distributing dylibs/frameworks in user’ s frameworks/application bundle
2014-04-21 03:32:05 +08:00
# NOTE : it's not required to link agains SFML.framework
2014-04-13 18:42:14 +08:00
set_target_properties ( SFML PROPERTIES
B U I L D _ W I T H _ I N S T A L L _ R P A T H 1
2011-12-15 02:54:44 +08:00
I N S T A L L _ N A M E _ D I R " @ e x e c u t a b l e _ p a t h / . . / F r a m e w o r k s " )
# install rule
install ( TARGETS SFML
F R A M E W O R K D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ F R A M E W O R K _ P R E F I X }
C O M P O N E N T d e v e l )
endif ( )
install ( FILES license.txt DESTINATION ${ INSTALL_MISC_DIR } )
2012-04-08 17:22:36 +08:00
install ( FILES readme.txt DESTINATION ${ INSTALL_MISC_DIR } )
2013-09-22 23:16:48 +08:00
if ( NOT SFML_OS_ANDROID )
install ( FILES cmake/Modules/FindSFML.cmake DESTINATION ${ INSTALL_MISC_DIR } /cmake/Modules )
2014-04-21 03:32:05 +08:00
endif ( )
2011-12-15 02:54:44 +08:00
2014-04-21 03:32:05 +08:00
# install 3rd-party libraries and tools
2013-10-09 14:01:10 +08:00
if ( SFML_OS_WINDOWS )
2013-09-13 22:09:22 +08:00
2014-04-21 03:32:05 +08:00
# install the binaries of SFML dependencies
2011-03-29 00:20:27 +08:00
if ( ARCH_32BITS )
2013-10-17 02:47:14 +08:00
install ( DIRECTORY extlibs/bin/x86/ DESTINATION bin )
if ( SFML_COMPILER_MSVC )
install ( DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib )
else ( )
install ( DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib )
endif ( )
2012-01-04 01:02:18 +08:00
elseif ( ARCH_64BITS )
2013-10-17 02:47:14 +08:00
install ( DIRECTORY extlibs/bin/x64/ DESTINATION bin )
if ( SFML_COMPILER_MSVC )
install ( DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib )
else ( )
install ( DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib )
endif ( )
2011-03-29 00:20:27 +08:00
endif ( )
2014-04-21 03:32:05 +08:00
2013-10-09 14:01:10 +08:00
elseif ( SFML_OS_MACOSX )
2013-09-13 22:09:22 +08:00
2014-04-21 03:32:05 +08:00
# install the non-standard frameworks SFML depends on
2011-12-15 02:54:44 +08:00
install ( DIRECTORY extlibs/libs-osx/Frameworks/sndfile.framework DESTINATION ${ CMAKE_INSTALL_FRAMEWORK_PREFIX } )
2013-01-19 23:20:01 +08:00
install ( DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${ CMAKE_INSTALL_FRAMEWORK_PREFIX } )
2011-12-15 02:54:44 +08:00
2013-09-13 22:09:22 +08:00
# install the Xcode templates if requested
2012-04-19 01:07:47 +08:00
if ( SFML_INSTALL_XCODE4_TEMPLATES )
2014-04-16 00:44:55 +08:00
install ( DIRECTORY tools/xcode/templates/SFML
D E S T I N A T I O N / L i b r a r y / D e v e l o p e r / X c o d e / T e m p l a t e s
P A T T E R N " * . i n " E X C L U D E )
configure_file (
" t o o l s / x c o d e / t e m p l a t e s / S F M L / S F M L C o m p i l e r . x c t e m p l a t e / T e m p l a t e I n f o . p l i s t . i n "
" / L i b r a r y / D e v e l o p e r / X c o d e / T e m p l a t e s / S F M L / S F M L C o m p i l e r . x c t e m p l a t e / T e m p l a t e I n f o . p l i s t "
@ O N L Y )
2011-08-20 18:14:55 +08:00
endif ( )
2013-09-13 22:09:22 +08:00
elseif ( SFML_OS_IOS )
# fix CMake install rules broken for iOS (see http://public.kitware.com/Bug/view.php?id=12506)
if ( SFML_OS_IOS )
install ( DIRECTORY "${CMAKE_BINARY_DIR}/lib/\$ENV{CONFIGURATION}/" DESTINATION lib ${ LIB_SUFFIX } )
endif ( )
# since the iOS libraries are built as static, we must install the SFML dependencies
# too so that the end user can easily link them to its final application
2013-08-20 03:53:50 +08:00
install ( FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib )
2013-09-13 22:09:22 +08:00
elseif ( SFML_OS_ANDROID )
2013-10-18 08:21:53 +08:00
# install extlibs
install ( DIRECTORY extlibs/libs-android/ ${ ANDROID_ABI } DESTINATION extlibs/lib )
install ( FILES extlibs/Android.mk DESTINATION extlibs )
# install Android.mk so the NDK knows how to set up SFML
2013-08-26 02:39:55 +08:00
install ( FILES src/SFML/Android.mk DESTINATION . )
2013-09-13 22:09:22 +08:00
2010-08-19 23:59:24 +08:00
endif ( )