2023-10-03 11:51:38 +08:00
if ( CMAKE_HOST_WIN32 )
# We require a CMake version greater than or equal to 3.24 on Windows in order to
# support specifying target_include_directories with SYSTEM for Visual Studio Generators
# see: https://cmake.org/cmake/help/latest/release/3.24.html#generators
cmake_minimum_required ( VERSION 3.24 )
else ( )
# For all other systems, 3.22 will suffice
cmake_minimum_required ( VERSION 3.22 )
endif ( )
2021-04-19 10:20:43 +08:00
2014-09-30 22:07:25 +08:00
# define a macro that helps defining an option
macro ( sfml_set_option var default type docstring )
if ( NOT DEFINED ${ var } )
set ( ${ var } ${ default } )
endif ( )
set ( ${ var } ${ ${var } } CACHE ${ type } ${ docstring } FORCE )
endmacro ( )
2015-01-30 22:37:06 +08:00
# these options have to be set before CMake detects/configures the toolchain
2023-11-05 02:59:47 +08:00
# use new MSVC debug information format specification mechanism if available
# we use this mechanism to embed debug information into the object file to allow ccache to cache it
if ( POLICY CMP0141 )
cmake_policy ( SET CMP0141 NEW )
endif ( )
2015-01-30 22:37:06 +08:00
# determine whether to create a debug or release build
2014-09-30 22:07:25 +08:00
sfml_set_option ( CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug or Release)" )
2023-04-04 05:36:33 +08:00
sfml_set_option ( CMAKE_OSX_DEPLOYMENT_TARGET "13.0" STRING "The minimal iOS version that will be able to run the built binaries. Cannot be lower than 13.0" )
2017-04-06 03:56:06 +08:00
2014-09-30 22:07:25 +08:00
# project name
2023-11-06 23:35:27 +08:00
project ( SFML VERSION 3.0.0 LANGUAGES CXX )
2022-01-20 13:46:10 +08:00
set ( VERSION_IS_RELEASE OFF )
2014-09-30 22:07:25 +08:00
# include the configuration file
2022-08-05 12:51:07 +08:00
include ( cmake/Config.cmake )
2014-09-30 22:07:25 +08:00
2019-04-09 18:02:17 +08:00
# we use the paths from the cmake GNUInstallDirs module as defaults
# you can override these if you like
2022-09-18 12:48:11 +08:00
# https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
2019-04-09 18:02:17 +08:00
include ( GNUInstallDirs )
2023-08-14 07:50:13 +08:00
# disable static libraries on Android
if ( SFML_OS_ANDROID )
2023-04-04 05:36:33 +08:00
set ( BUILD_SHARED_LIBS TRUE )
2014-09-30 22:07:25 +08:00
endif ( )
2015-02-21 21:46:46 +08:00
# add options to select which modules to build
sfml_set_option ( SFML_BUILD_WINDOW TRUE BOOL "TRUE to build SFML's Window module. This setting is ignored, if the graphics module is built." )
sfml_set_option ( SFML_BUILD_GRAPHICS TRUE BOOL "TRUE to build SFML's Graphics module." )
2018-01-05 06:23:49 +08:00
sfml_set_option ( SFML_BUILD_AUDIO TRUE BOOL "TRUE to build SFML's Audio module." )
2015-02-21 21:46:46 +08:00
sfml_set_option ( SFML_BUILD_NETWORK TRUE BOOL "TRUE to build SFML's Network module." )
if ( SFML_BUILD_WINDOW )
2022-10-24 08:45:40 +08:00
# add an option for choosing the OpenGL implementation
2015-02-21 21:46:46 +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" )
2022-10-24 08:45:40 +08:00
# add an option for choosing whether to use the DRM windowing backend
if ( SFML_OS_LINUX )
sfml_set_option ( SFML_USE_DRM FALSE BOOL "TRUE to use DRM windowing backend" )
endif ( )
2015-02-21 21:46:46 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
2018-04-12 03:45:36 +08:00
# macOS specific options
2023-02-12 12:49:05 +08:00
if ( SFML_OS_MACOS OR SFML_OS_IOS )
2014-09-30 22:07:25 +08:00
# add an option to build frameworks instead of dylibs (release only)
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" )
# add an option to automatically install Xcode templates
sfml_set_option ( SFML_INSTALL_XCODE_TEMPLATES FALSE BOOL "TRUE to automatically install the Xcode templates, FALSE to do nothing about it. The templates are compatible with Xcode 4 and 5." )
endif ( )
# Android options
if ( SFML_OS_ANDROID )
2021-12-06 22:49:05 +08:00
sfml_set_option ( SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK FALSE BOOL "TRUE to use an sf::Clock implementation which takes system sleep time into account (keeps advancing during suspension), FALSE to default to another available monotonic clock" )
2022-10-07 01:33:19 +08:00
if ( SFML_ANDROID_USE_SUSPEND_AWARE_CLOCK )
2021-12-06 22:49:05 +08:00
add_definitions ( -DSFML_ANDROID_USE_SUSPEND_AWARE_CLOCK )
endif ( )
2019-04-09 01:17:26 +08:00
# avoid missing libraries when building SFML for Android with NDK r19c and later
2022-08-07 13:50:47 +08:00
list ( PREPEND CMAKE_FIND_ROOT_PATH "${PROJECT_SOURCE_DIR}" )
2019-04-09 01:17:26 +08:00
2014-09-30 22:07:25 +08:00
# install everything in $NDK/sources/ because this path is appended by the NDK (convenient)
2018-01-25 22:06:30 +08:00
set ( CMAKE_INSTALL_PREFIX ${ CMAKE_ANDROID_NDK } /sources/third_party/sfml )
2014-09-30 22:07:25 +08:00
2019-04-09 18:02:17 +08:00
# we install libs in a subdirectory named after the ABI
set ( CMAKE_INSTALL_LIBDIR "${CMAKE_INSTALL_LIBDIR}/${CMAKE_ANDROID_ARCH_ABI}" )
2014-09-30 22:07:25 +08:00
endif ( )
2018-03-21 02:46:57 +08:00
# Install directories
# For miscellaneous files
if ( SFML_OS_WINDOWS OR SFML_OS_IOS )
set ( DEFAULT_INSTALL_MISC_DIR . )
2020-12-05 15:41:26 +08:00
elseif ( SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD )
2018-03-21 02:46:57 +08:00
set ( DEFAULT_INSTALL_MISC_DIR share/SFML )
2023-02-12 12:49:05 +08:00
elseif ( SFML_OS_MACOS )
2018-03-21 02:46:57 +08:00
set ( DEFAULT_INSTALL_MISC_DIR /usr/local/share/SFML )
elseif ( SFML_OS_ANDROID )
set ( DEFAULT_INSTALL_MISC_DIR ${ CMAKE_ANDROID_NDK } /sources/third_party/sfml )
2014-09-30 22:07:25 +08:00
endif ( )
2015-02-21 21:46:46 +08:00
# force building sfml-window, if sfml-graphics module is built
if ( SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW )
message ( WARNING "You're trying to build SFML's Graphics module without the Window module. Forcing building of the Window module as a dependency." )
set ( SFML_BUILD_WINDOW TRUE )
endif ( )
2016-12-20 05:16:07 +08:00
# allow not using bundled dependencies with a switch
# (except for stb_image)
# yes this is horrible, but GLOB_RECURSE sucks
sfml_set_option ( SFML_USE_SYSTEM_DEPS FALSE BOOL "TRUE to use system dependencies, FALSE to use the bundled ones." )
if ( SFML_USE_SYSTEM_DEPS )
if ( SFML_INSTALL_XCODE_TEMPLATES )
message ( FATAL_ERROR "XCode templates installation cannot be used with the SFML_USE_SYSTEM_DEPS option (the bundled frameworks are required.)" )
endif ( )
2022-08-28 12:45:15 +08:00
file ( GLOB_RECURSE DEP_LIBS "${PROJECT_SOURCE_DIR}/extlibs/libs*/*" )
file ( GLOB_RECURSE DEP_BINS "${PROJECT_SOURCE_DIR}/extlibs/bin*/*" )
file ( GLOB_RECURSE DEP_HEADERS "${PROJECT_SOURCE_DIR}/extlibs/headers/*" )
2016-12-20 05:16:07 +08:00
foreach ( DEP_FILE ${ DEP_LIBS } ${ DEP_BINS } ${ DEP_HEADERS } )
get_filename_component ( DEP_DIR ${ DEP_FILE } PATH )
2021-12-06 19:32:36 +08:00
if ( NOT DEP_DIR MATCHES "/(stb_image|minimp3)(/|$)" )
list ( APPEND CMAKE_IGNORE_PATH "${DEP_DIR}" )
2016-12-20 05:16:07 +08:00
endif ( )
get_filename_component ( DEP_PARENT_DIR ${ DEP_DIR } PATH )
2022-08-28 12:45:15 +08:00
while ( NOT DEP_PARENT_DIR STREQUAL "${PROJECT_SOURCE_DIR}/extlibs" )
2021-12-06 19:32:36 +08:00
if ( NOT DEP_DIR MATCHES "/(stb_image|minimp3)(/|$)" )
list ( APPEND CMAKE_IGNORE_PATH "${DEP_PARENT_DIR}" )
2016-12-20 05:16:07 +08:00
endif ( )
get_filename_component ( DEP_PARENT_DIR ${ DEP_PARENT_DIR } PATH )
endwhile ( )
endforeach ( )
list ( REMOVE_DUPLICATES CMAKE_IGNORE_PATH )
2023-12-10 22:10:07 +08:00
elseif ( SFML_COMPILER_GCC AND GCC_COMPILER_VERSION MATCHES "ucrt" )
message ( FATAL_ERROR "The pre-compiled SFML dependencies for MinGW are not compatible with the UCRT. Either switch to the MSVCRT or build the dependencies yourself." )
2016-12-20 05:16:07 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
if ( SFML_COMPILER_MSVC )
2016-01-01 21:18:13 +08:00
# add an option to choose whether PDB debug symbols should be generated (defaults to true when possible)
2022-08-05 13:46:27 +08:00
sfml_set_option ( SFML_GENERATE_PDB TRUE BOOL "True to generate PDB debug symbols, FALSE otherwise." )
2023-11-05 02:59:47 +08:00
# if building using a compiler launcher, embed the MSVC debugging information to allow for caching
if ( CMAKE_CXX_COMPILER_LAUNCHER )
set ( CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>" )
endif ( )
2014-09-30 22:07:25 +08:00
endif ( )
# define SFML_OPENGL_ES if needed
if ( SFML_OPENGL_ES )
add_definitions ( -DSFML_OPENGL_ES )
add_definitions ( -DGL_GLEXT_PROTOTYPES )
endif ( )
# define an option for choosing between static and dynamic C runtime (Windows only)
if ( SFML_OS_WINDOWS )
sfml_set_option ( SFML_USE_STATIC_STD_LIBS FALSE BOOL "TRUE to statically link to the standard libraries, FALSE to use them as DLLs" )
# the following combination of flags is not valid
2021-05-04 02:09:34 +08:00
if ( BUILD_SHARED_LIBS AND SFML_USE_STATIC_STD_LIBS )
2014-09-30 22:07:25 +08:00
message ( FATAL_ERROR "BUILD_SHARED_LIBS and SFML_USE_STATIC_STD_LIBS cannot be used together" )
endif ( )
2023-03-26 20:21:21 +08:00
sfml_set_option ( SFML_USE_MESA3D FALSE BOOL "TRUE to use the Mesa 3D graphics library for rendering, FALSE to use the system provided library for rendering" )
include ( cmake/Mesa3D.cmake )
2014-09-30 22:07:25 +08:00
endif ( )
2023-02-12 12:49:05 +08:00
# setup macOS stuff
if ( SFML_OS_MACOS )
2014-09-30 22:07:25 +08:00
# SFML_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 ( SFML_BUILD_FRAMEWORKS )
# requirement #1
if ( NOT CMAKE_BUILD_TYPE STREQUAL "Release" )
message ( FATAL_ERROR "CMAKE_BUILD_TYPE should be \" Release\ " when SFML_BUILD_FRAMEWORKS is TRUE" )
return ( )
endif ( )
# requirement #2
if ( NOT BUILD_SHARED_LIBS )
message ( FATAL_ERROR "BUILD_SHARED_LIBS should be TRUE when SFML_BUILD_FRAMEWORKS is TRUE" )
return ( )
endif ( )
endif ( )
2016-04-01 01:05:08 +08:00
# configure Xcode templates
set ( XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)" )
2023-09-26 11:14:26 +08:00
if ( NOT SFML_COMPILER_CLANG )
message ( FATAL_ERROR "Clang is the only supported compiler on macOS" )
endif ( )
2014-09-30 22:07:25 +08:00
endif ( )
2023-10-27 07:28:40 +08:00
option ( SFML_ENABLE_SANITIZERS "Enable sanitizers" OFF )
if ( SFML_ENABLE_SANITIZERS )
2024-03-28 10:32:34 +08:00
string ( APPEND CMAKE_CXX_FLAGS " -fno-omit-frame-pointer -fno-sanitize-recover=all -fsanitize=undefined" )
2023-10-27 07:28:40 +08:00
endif ( )
2022-07-18 06:20:02 +08:00
# set the output directory for SFML DLLs and executables
set ( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${ PROJECT_BINARY_DIR } /bin )
2014-09-30 22:07:25 +08:00
# enable project folders
set_property ( GLOBAL PROPERTY USE_FOLDERS ON )
set_property ( GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake" )
# add the subdirectories
add_subdirectory ( src/SFML )
2018-08-10 04:20:35 +08:00
# on Linux and BSD-like OS, install pkg-config files by default
set ( SFML_INSTALL_PKGCONFIG_DEFAULT FALSE )
2020-12-05 15:41:26 +08:00
if ( SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD )
2018-08-10 04:20:35 +08:00
set ( SFML_INSTALL_PKGCONFIG_DEFAULT TRUE )
endif ( )
sfml_set_option ( SFML_INSTALL_PKGCONFIG_FILES ${ SFML_INSTALL_PKGCONFIG_DEFAULT } BOOL "TRUE to automatically install pkg-config files so other projects can find SFML" )
if ( SFML_INSTALL_PKGCONFIG_FILES )
2023-11-14 11:13:27 +08:00
# set pkgconfig install directory
# this could be e.g. macports on mac or msys2 on windows etc.
set ( SFML_PKGCONFIG_DIR "/${CMAKE_INSTALL_LIBDIR}/pkgconfig" )
if ( SFML_OS_FREEBSD OR SFML_OS_OPENBSD OR SFML_OS_NETBSD )
set ( SFML_PKGCONFIG_DIR "/libdata/pkgconfig" )
endif ( )
2018-08-10 04:20:35 +08:00
sfml_set_option ( SFML_PKGCONFIG_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/${SFML_PKGCONFIG_DIR}" PATH "Install directory for SFML's pkg-config .pc files" )
2016-12-20 05:16:07 +08:00
foreach ( sfml_module IN ITEMS all system window graphics audio network )
2023-01-31 06:28:32 +08:00
configure_file (
2016-12-20 05:16:07 +08:00
" 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 )
2023-01-31 06:28:32 +08:00
install ( FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
2018-08-10 04:20:35 +08:00
D E S T I N A T I O N " $ { S F M L _ P K G C O N F I G _ I N S T A L L _ P R E F I X } " )
2016-12-20 05:16:07 +08:00
endforeach ( )
endif ( )
2022-10-08 05:38:45 +08:00
# option to enable precompiled headers
sfml_set_option ( SFML_ENABLE_PCH FALSE BOOL "TRUE to enable precompiled headers for SFML builds -- only supported on Windows/Linux and for static library builds" )
if ( SFML_ENABLE_PCH AND BUILD_SHARED_LIBS )
message ( FATAL_ERROR "Precompiled headers are currently not supported for shared library builds" )
endif ( )
2023-02-12 12:49:05 +08:00
if ( SFML_ENABLE_PCH AND SFML_OS_MACOS )
message ( FATAL_ERROR "Precompiled headers are currently not supported in macOS builds" )
2022-10-08 05:38:45 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
# setup the install rules
if ( NOT SFML_BUILD_FRAMEWORKS )
2022-08-28 11:39:18 +08:00
install ( DIRECTORY include/
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ I N C L U D E D I R }
2014-09-30 22:07:25 +08:00
C O M P O N E N T d e v e l
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 " )
2023-08-15 15:39:53 +08:00
install ( DIRECTORY cmake/Modules/
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B D I R } / c m a k e / S F M L
C O M P O N E N T d e v e l )
2015-12-31 03:30:59 +08:00
2016-01-01 21:18:13 +08:00
if ( SFML_GENERATE_PDB )
2022-08-28 11:39:18 +08:00
install ( DIRECTORY ${ PROJECT_BINARY_DIR } /lib/
D E S T I N A T I O N $ { C M A K E _ I N S T A L L _ L I B D I R }
2016-01-01 21:18:13 +08:00
C O M P O N E N T d e v e l
F I L E S _ M A T C H I N G P A T T E R N " * . p d b " )
endif ( )
2014-09-30 22:07:25 +08:00
else ( )
# find only "root" headers
file ( GLOB SFML_HEADERS RELATIVE ${ PROJECT_SOURCE_DIR } "include/SFML/*" )
2023-04-04 05:36:33 +08:00
# Because we use generator expressions in the post build scripts we need to
# suppress the generation of "EFFECTIVE_PLATFORM_NAME" as it will fail
set_property ( GLOBAL PROPERTY XCODE_EMIT_EFFECTIVE_PLATFORM_NAME OFF )
2014-09-30 22:07:25 +08:00
# 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
2022-09-15 00:42:13 +08:00
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
V E R B A T I M )
2014-09-30 22:07:25 +08:00
set ( SFML_SOURCES ${ SFML_HEADERS } )
list ( APPEND SFML_SOURCES ${ CMAKE_CURRENT_BINARY_DIR } /dummy.cpp )
# create SFML.framework
add_library ( SFML ${ SFML_SOURCES } )
2021-12-02 03:14:15 +08:00
# enable C++17 support
target_compile_features ( SFML PUBLIC cxx_std_17 )
2018-01-29 01:35:00 +08:00
# set the target flags to use the appropriate C++ standard library
sfml_set_stdlib ( SFML )
2014-09-30 22:07:25 +08:00
# edit target properties
set_target_properties ( SFML PROPERTIES
F R A M E W O R K T R U E
2022-01-20 13:46:10 +08:00
F R A M E W O R K _ V E R S I O N $ { P R O J E C T _ V E R S I O N }
2014-09-30 22:07:25 +08:00
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
2022-01-20 13:46:10 +08:00
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 $ { P R O J E C T _ V E R S I O N }
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 $ { P R O J E C T _ V E R S I O N }
2014-09-30 22:07:25 +08:00
P U B L I C _ H E A D E R " $ { S F M L _ H E A D E R S } " )
2015-02-21 21:46:46 +08:00
# add the non-optional SFML headers
add_custom_command ( TARGET SFML POST_BUILD COMMAND cp -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 / C o n f i g . h p p
$ { 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 / O p e n G L . h p p
2018-04-07 08:17:05 +08:00
$ { 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 / G p u P r e f e r e n c e . h p p
2015-02-21 21:46:46 +08:00
$ { 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 / S y s t e m . h p p
$ { 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 / M a i n . h p p
$ { 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 / S y s t e m
2022-09-15 00:42:13 +08:00
$ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s
V E R B A T I M )
2015-02-21 21:46:46 +08:00
# add window module headers if enabled
if ( SFML_BUILD_WINDOW )
add_custom_command ( TARGET SFML POST_BUILD COMMAND cp -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 / W i n d o w . h p p
$ { 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 / W i n d o w
2022-09-15 00:42:13 +08:00
$ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s
V E R B A T I M )
2015-02-21 21:46:46 +08:00
endif ( )
# add network module headers if enabled
2017-07-19 12:40:34 +08:00
if ( SFML_BUILD_NETWORK )
2015-02-21 21:46:46 +08:00
add_custom_command ( TARGET SFML POST_BUILD COMMAND cp -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 / N e t w o r k . h p p
$ { 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 / N e t w o r k
2022-09-15 00:42:13 +08:00
$ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s
V E R B A T I M )
2015-02-21 21:46:46 +08:00
endif ( )
# add graphics module headers if enabled
if ( SFML_BUILD_GRAPHICS )
add_custom_command ( TARGET SFML POST_BUILD COMMAND cp -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 / G r a p h i c s . h p p
$ { 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 / G r a p h i c s
2022-09-15 00:42:13 +08:00
$ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s
V E R B A T I M )
2015-02-21 21:46:46 +08:00
endif ( )
# add audio module headers if enabled
if ( SFML_BUILD_AUDIO )
add_custom_command ( TARGET SFML POST_BUILD COMMAND cp -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 / A u d i o . h p p
$ { 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 / A u d i o
2022-09-15 00:42:13 +08:00
$ < T A R G E T _ F I L E _ D I R : S F M L > / H e a d e r s
V E R B A T I M )
2015-02-21 21:46:46 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
2015-03-10 07:56:04 +08:00
# adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle
2016-04-01 01:05:08 +08:00
# NOTE: it's not required to link against SFML.framework
2018-02-11 01:07:21 +08:00
set_target_properties ( SFML PROPERTIES INSTALL_NAME_DIR "@rpath" )
if ( NOT CMAKE_SKIP_BUILD_RPATH )
2023-12-11 12:40:07 +08:00
set_target_properties ( SFML PROPERTIES BUILD_WITH_INSTALL_NAME_DIR TRUE )
2018-02-11 01:07:21 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
# install rule
install ( TARGETS SFML
2018-03-21 02:46:57 +08:00
F R A M E W O R K D E S T I N A T I O N " . "
2014-09-30 22:07:25 +08:00
C O M P O N E N T d e v e l )
endif ( )
2019-04-09 18:02:17 +08:00
install ( FILES license.md DESTINATION ${ CMAKE_INSTALL_DOCDIR } )
install ( FILES readme.md DESTINATION ${ CMAKE_INSTALL_DOCDIR } )
2014-09-30 22:07:25 +08:00
# install 3rd-party libraries and tools
if ( SFML_OS_WINDOWS )
2017-06-02 16:57:15 +08:00
if ( NOT SFML_USE_SYSTEM_DEPS )
# install the binaries of SFML dependencies
if ( ARCH_32BITS )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/bin/x86/ DESTINATION ${ CMAKE_INSTALL_BINDIR } )
2021-12-19 23:17:00 +08:00
if ( SFML_COMPILER_MSVC OR ( SFML_COMPILER_CLANG AND NOT MINGW ) )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/libs-msvc-universal/x86/ DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2017-06-02 16:57:15 +08:00
else ( )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/libs-mingw/x86/ DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2017-06-02 16:57:15 +08:00
endif ( )
elseif ( ARCH_64BITS )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/bin/x64/ DESTINATION ${ CMAKE_INSTALL_BINDIR } )
2021-12-19 23:17:00 +08:00
if ( SFML_COMPILER_MSVC OR ( SFML_COMPILER_CLANG AND NOT MINGW ) )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/libs-msvc-universal/x64/ DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2017-06-02 16:57:15 +08:00
else ( )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY extlibs/libs-mingw/x64/ DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2017-06-02 16:57:15 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
endif ( )
endif ( )
2023-02-12 12:49:05 +08:00
elseif ( SFML_OS_MACOS )
2015-01-08 23:21:39 +08:00
# install extlibs dependencies only when used
2015-02-21 21:46:46 +08:00
if ( SFML_BUILD_GRAPHICS )
2023-02-12 12:49:05 +08:00
if ( FREETYPE_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/freetype.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/freetype.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2015-01-08 23:21:39 +08:00
endif ( )
2015-02-21 21:46:46 +08:00
if ( SFML_BUILD_AUDIO )
2023-02-12 12:49:05 +08:00
if ( FLAC_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/FLAC.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/FLAC.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
2023-02-12 12:49:05 +08:00
if ( OGG_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/ogg.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/ogg.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2014-10-29 01:00:51 +08:00
2023-02-12 12:49:05 +08:00
if ( VORBIS_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/vorbis.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/vorbis.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2014-10-29 01:00:51 +08:00
2023-02-12 12:49:05 +08:00
if ( VORBISENC_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/vorbisenc.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/vorbisenc.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2014-10-29 01:00:51 +08:00
2023-02-12 12:49:05 +08:00
if ( VORBISFILE_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/vorbisfile.framework" )
install ( DIRECTORY extlibs/libs-macos/Frameworks/vorbisfile.framework DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2014-10-29 01:00:51 +08:00
2023-02-12 12:49:05 +08:00
if ( OPENAL_LIBRARY STREQUAL "${PROJECT_SOURCE_DIR}/extlibs/libs-macos/Frameworks/OpenAL.framework" )
2019-04-09 18:02:17 +08:00
install ( DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${ CMAKE_INSTALL_LIBDIR } )
2015-02-21 21:46:46 +08:00
endif ( )
2015-03-14 19:15:41 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
# install the Xcode templates if requested
if ( SFML_INSTALL_XCODE_TEMPLATES )
2014-10-08 17:08:04 +08:00
# configure the templates plist files
foreach ( TEMPLATE "SFML Compiler" "SFML App" )
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 / $ { T E M P L A T E } . 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 "
" $ { C M A K E _ C U R R E N T _ B I N A R Y _ D I R } / t o o l s / x c o d e / t e m p l a t e s / S F M L / $ { T E M P L A T E } . 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 )
endforeach ( )
2014-09-30 22:07:25 +08:00
install ( DIRECTORY "tools/xcode/templates/SFML" "${CMAKE_CURRENT_BINARY_DIR}/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
2014-10-08 17:08:04 +08:00
P A T T E R N " * . i n " E X C L U D E
P A T T E R N " . D S _ S t o r e " E X C L U D E )
2014-09-30 22:07:25 +08:00
endif ( )
elseif ( SFML_OS_IOS )
2017-06-02 16:57:15 +08:00
if ( NOT SFML_USE_SYSTEM_DEPS )
# 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
if ( SFML_BUILD_GRAPHICS )
2017-09-08 15:38:51 +08:00
install ( FILES extlibs/libs-ios/libfreetype.a DESTINATION lib )
2017-06-02 16:57:15 +08:00
endif ( )
2018-01-25 08:52:07 +08:00
if ( SFML_BUILD_AUDIO )
2018-04-12 03:45:36 +08:00
install ( FILES extlibs/libs-ios/libflac.a
2018-01-25 08:52:07 +08:00
e x t l i b s / l i b s - i o s / l i b v o r b i s . a
e x t l i b s / l i b s - i o s / l i b o g g . a
D E S T I N A T I O N l i b )
endif ( )
2015-02-21 21:46:46 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
elseif ( SFML_OS_ANDROID )
2017-06-02 16:57:15 +08:00
if ( NOT SFML_USE_SYSTEM_DEPS )
# install extlibs
2018-01-25 22:06:30 +08:00
install ( DIRECTORY extlibs/libs-android/ ${ CMAKE_ANDROID_ARCH_ABI } DESTINATION extlibs/lib )
2017-06-02 16:57:15 +08:00
endif ( )
2014-09-30 22:07:25 +08:00
endif ( )
2018-03-21 02:47:29 +08:00
sfml_export_targets ( )
2016-07-21 21:35:48 +08:00
set ( CPACK_PACKAGE_NAME_SUMMARY "Simple and Fast Multimedia Library" )
set ( CPACK_PACKAGE_VENDOR "SFML Team" )
2022-01-20 13:46:10 +08:00
set ( CPACK_PACKAGE_FILE_NAME "SFML-${PROJECT_VERSION}-${CMAKE_CXX_COMPILER_ID}-${CMAKE_CXX_COMPILER_VERSION}-${CMAKE_BUILD_TYPE}" )
2016-07-21 21:35:48 +08:00
set ( CPACK_RESOURCE_FILE_README "${CMAKE_CURRENT_SOURCE_DIR}/readme.md" )
set ( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/license.md" )
2022-01-20 13:46:10 +08:00
set ( CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}" )
set ( CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}" )
set ( CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}" )
set ( CPACK_PACKAGE_INSTALL_DIRECTORY "SFML ${PROJECT_VERSION}" )
2016-07-21 21:35:48 +08:00
set ( CPACK_MONOLITHIC_INSTALL ON )
# NSIS configurations
2022-01-20 13:46:10 +08:00
set ( CPACK_NSIS_DISPLAY_NAME "SFML ${PROJECT_VERSION} (${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION})" )
2016-07-21 21:35:48 +08:00
set ( CPACK_NSIS_CONTACT "team@sfml-dev.org" )
set ( NSIS_IMAGE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/tools/nsis/" )
string ( REGEX REPLACE "/" "\\\\\\\\" NSIS_IMAGE_PATH ${ NSIS_IMAGE_PATH } )
set ( CPACK_NSIS_INSTALLER_MUI_ICON_CODE "!define MUI_WELCOMEFINISHPAGE_BITMAP \\\" ${ NSIS_IMAGE_PATH } sidebar.bmp\\\ "\n!define MUI_HEADERIMAGE_BITMAP \\\" ${ NSIS_IMAGE_PATH } header.bmp\\\ "\n!define MUI_ICON \\\" ${ NSIS_IMAGE_PATH } sfml.ico\\\ "" )
include ( CPack )
2022-02-18 03:32:28 +08:00
2022-08-08 12:42:40 +08:00
# configure extras by default when building SFML directly, otherwise hide them
2023-05-09 07:17:20 +08:00
sfml_set_option ( SFML_CONFIGURE_EXTRAS ${ PROJECT_IS_TOP_LEVEL } BOOL "TRUE to configure extras, FALSE to ignore them" )
2022-08-08 12:42:40 +08:00
if ( NOT SFML_CONFIGURE_EXTRAS )
2022-02-18 03:32:28 +08:00
return ( )
endif ( )
2022-08-08 12:42:40 +08:00
# add an option for building the API documentation
sfml_set_option ( SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it" )
if ( SFML_BUILD_DOC )
add_subdirectory ( doc )
endif ( )
# add an option for building the examples
sfml_set_option ( SFML_BUILD_EXAMPLES FALSE BOOL "TRUE to build the SFML examples, FALSE to ignore them" )
if ( SFML_BUILD_EXAMPLES AND NOT SFML_OS_ANDROID )
add_subdirectory ( examples )
endif ( )
# add an option for building the test suite
sfml_set_option ( SFML_BUILD_TEST_SUITE FALSE BOOL "TRUE to build the SFML test suite, FALSE to ignore it" )
# add an option for enabling coverage reporting
sfml_set_option ( SFML_ENABLE_COVERAGE FALSE BOOL "TRUE to enable coverage reporting, FALSE to ignore it" )
if ( SFML_BUILD_TEST_SUITE )
2024-04-12 07:38:14 +08:00
if ( SFML_BUILD_WINDOW AND SFML_BUILD_GRAPHICS AND SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO )
2022-08-08 12:42:40 +08:00
enable_testing ( )
add_subdirectory ( test )
else ( )
message ( WARNING "Cannot build unit testing unless all modules are enabled" )
endif ( )
endif ( )
2022-11-26 03:08:15 +08:00
sfml_set_option ( CLANG_FORMAT_EXECUTABLE clang-format STRING "Override clang-format executable, requires version 12, 13, or 14" )
2022-02-18 03:32:28 +08:00
add_custom_target ( format
2022-10-25 12:59:56 +08:00
C O M M A N D $ { C M A K E _ C O M M A N D } - D C L A N G _ F O R M A T _ E X E C U T A B L E = $ { C L A N G _ F O R M A T _ E X E C U T A B L E } - P . / c m a k e / F o r m a t . c m a k e
W O R K I N G _ D I R E C T O R Y $ { P R O J E C T _ S O U R C E _ D I R } V E R B A T I M )
2022-10-17 04:30:13 +08:00
2022-10-24 06:53:36 +08:00
sfml_set_option ( CLANG_TIDY_EXECUTABLE clang-tidy STRING "Override clang-tidy executable, requires minimum version 14" )
2022-10-25 12:59:56 +08:00
add_custom_target ( tidy
C O M M A N D $ { C M A K E _ C O M M A N D } - D C L A N G _ T I D Y _ E X E C U T A B L E = $ { C L A N G _ T I D Y _ E X E C U T A B L E } - D P R O J E C T _ B I N A R Y _ D I R = $ { P R O J E C T _ B I N A R Y _ D I R } - P . / c m a k e / T i d y . c m a k e
W O R K I N G _ D I R E C T O R Y $ { P R O J E C T _ S O U R C E _ D I R } V E R B A T I M )