Modernize CMake files

This commit is contained in:
Ceylo 2018-03-20 19:46:57 +01:00 committed by Lukas Dürrenberger
parent fc02cf004a
commit ee08e18726
26 changed files with 259 additions and 275 deletions

View File

@ -2,7 +2,7 @@
if(CMAKE_SYSTEM_NAME MATCHES "Android") if(CMAKE_SYSTEM_NAME MATCHES "Android")
cmake_minimum_required(VERSION 3.7.2) cmake_minimum_required(VERSION 3.7.2)
else() else()
cmake_minimum_required(VERSION 2.8.3) cmake_minimum_required(VERSION 3.0.2)
endif() endif()
# define a macro that helps defining an option # define a macro that helps defining an option
@ -22,9 +22,7 @@ sfml_set_option(CMAKE_BUILD_TYPE Release STRING "Choose the type of build (Debug
set(CMAKE_LEGACY_CYGWIN_WIN32 0) set(CMAKE_LEGACY_CYGWIN_WIN32 0)
# Suppress Mac OS X RPATH warnings and adopt new related behaviors # Suppress Mac OS X RPATH warnings and adopt new related behaviors
if(NOT CMAKE_VERSION VERSION_LESS 3.0)
cmake_policy(SET CMP0042 NEW) cmake_policy(SET CMP0042 NEW)
endif()
if (NOT CMAKE_VERSION VERSION_LESS 3.9) if (NOT CMAKE_VERSION VERSION_LESS 3.9)
cmake_policy(SET CMP0068 NEW) cmake_policy(SET CMP0068 NEW)
endif() endif()
@ -57,9 +55,6 @@ set(VERSION_MAJOR 2)
set(VERSION_MINOR 4) set(VERSION_MINOR 4)
set(VERSION_PATCH 2) set(VERSION_PATCH 2)
# add the SFML header path
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)
if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID)) if(NOT (SFML_OS_IOS OR SFML_OS_ANDROID))
sfml_set_option(BUILD_SHARED_LIBS TRUE 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")
@ -97,11 +92,14 @@ if(SFML_OS_MACOSX)
# add an option to build frameworks instead of dylibs (release only) # 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") 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 let the user specify a custom directory for frameworks installation (SFML, FLAC, ...) # add an option to let the user specify a custom directory for external frameworks installation
sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory") sfml_set_option(SFML_DEPENDENCIES_INSTALL_PREFIX "/Library/Frameworks" PATH "External frameworks (FLAC, Freetype, Vorbis, ...) installation directory")
# add an option to automatically install Xcode templates # 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.") 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.")
else()
# add an option to let the user specify a custom directory for external libraries installation
sfml_set_option(SFML_DEPENDENCIES_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" PATH "External libraries (FLAC, Freetype, Vorbis, ...) installation directory")
endif() endif()
# Android options # Android options
@ -141,10 +139,20 @@ if(SFML_OS_ANDROID)
set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL "<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>") set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL "<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>")
endif() endif()
# define SFML_STATIC if the build type is not set to 'shared' # Install directories
if(NOT BUILD_SHARED_LIBS) # For miscellaneous files
add_definitions(-DSFML_STATIC) if(SFML_OS_WINDOWS OR SFML_OS_IOS)
set(DEFAULT_INSTALL_MISC_DIR .)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
set(DEFAULT_INSTALL_MISC_DIR share/SFML)
elseif(SFML_OS_MACOSX)
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)
endif() endif()
# add an option to let the user specify a custom directory for doc, examples, licence, readme and other miscellaneous files
sfml_set_option(SFML_MISC_INSTALL_PREFIX "${DEFAULT_INSTALL_MISC_DIR}" PATH "Prefix installation path for miscellaneous files")
# force building sfml-window, if sfml-graphics module is built # force building sfml-window, if sfml-graphics module is built
if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW) if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW)
@ -408,15 +416,12 @@ else()
# install rule # install rule
install(TARGETS SFML install(TARGETS SFML
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} FRAMEWORK DESTINATION "."
COMPONENT devel) COMPONENT devel)
endif() endif()
install(FILES license.md DESTINATION ${INSTALL_MISC_DIR}) install(FILES license.md DESTINATION ${SFML_MISC_INSTALL_PREFIX})
install(FILES readme.md DESTINATION ${INSTALL_MISC_DIR}) install(FILES readme.md DESTINATION ${SFML_MISC_INSTALL_PREFIX})
if(NOT SFML_OS_ANDROID)
install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules)
endif()
# install 3rd-party libraries and tools # install 3rd-party libraries and tools
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
@ -424,58 +429,57 @@ if(SFML_OS_WINDOWS)
if(NOT SFML_USE_SYSTEM_DEPS) if(NOT SFML_USE_SYSTEM_DEPS)
# install the binaries of SFML dependencies # install the binaries of SFML dependencies
if(ARCH_32BITS) if(ARCH_32BITS)
install(DIRECTORY extlibs/bin/x86/ DESTINATION bin) install(DIRECTORY extlibs/bin/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/bin)
if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14) if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib) install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
elseif(SFML_COMPILER_MSVC) elseif(SFML_COMPILER_MSVC)
install(DIRECTORY extlibs/libs-msvc-universal/x86/ DESTINATION lib) install(DIRECTORY extlibs/libs-msvc-universal/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
else() else()
install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib) install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
endif() endif()
elseif(ARCH_64BITS) elseif(ARCH_64BITS)
install(DIRECTORY extlibs/bin/x64/ DESTINATION bin) install(DIRECTORY extlibs/bin/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/bin)
if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14) if(SFML_COMPILER_MSVC AND SFML_MSVC_VERSION LESS 14)
install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib) install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
elseif(SFML_COMPILER_MSVC) elseif(SFML_COMPILER_MSVC)
install(DIRECTORY extlibs/libs-msvc-universal/x64/ DESTINATION lib) install(DIRECTORY extlibs/libs-msvc-universal/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
else() else()
install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib) install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib)
endif() endif()
endif() endif()
endif() endif()
elseif(SFML_OS_MACOSX) elseif(SFML_OS_MACOSX)
# install extlibs dependencies only when used # install extlibs dependencies only when used
if(SFML_BUILD_GRAPHICS) if(SFML_BUILD_GRAPHICS)
if(FREETYPE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework") if(FREETYPE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
endif() endif()
if(SFML_BUILD_AUDIO) if(SFML_BUILD_AUDIO)
if(FLAC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework") if(FLAC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework") if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/ogg.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
if(VORBIS_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework") if(VORBIS_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/vorbis.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
if(VORBISENC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework") if(VORBISENC_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
if(VORBISFILE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework") if(VORBISFILE_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework") if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework")
install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX})
endif() endif()
endif() endif()

View File

@ -81,7 +81,7 @@ endif()
# detect the compiler and its version # detect the compiler and its version
# Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true # Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true
# even when CLANG is used, therefore the Clang test is done first # even when CLANG is used, therefore the Clang test is done first
if(CMAKE_CXX_COMPILER MATCHES ".*clang[+][+]" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") if(CMAKE_CXX_COMPILER MATCHES "clang[+][+]" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change, # CMAKE_CXX_COMPILER_ID is an internal CMake variable subject to change,
# but there is no other way to detect CLang at the moment # but there is no other way to detect CLang at the moment
set(SFML_COMPILER_CLANG 1) set(SFML_COMPILER_CLANG 1)
@ -117,12 +117,3 @@ else()
message(FATAL_ERROR "Unsupported compiler") message(FATAL_ERROR "Unsupported compiler")
return() return()
endif() endif()
# define the install directory for miscellaneous files
if(SFML_OS_WINDOWS OR SFML_OS_IOS)
set(INSTALL_MISC_DIR .)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
set(INSTALL_MISC_DIR share/SFML)
elseif(SFML_OS_ANDROID)
set(INSTALL_MISC_DIR ${CMAKE_ANDROID_NDK}/sources/third_party/sfml)
endif()

View File

@ -6,9 +6,9 @@ function(sfml_set_stdlib target)
# for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled # for gcc >= 4.0 on Windows, apply the SFML_USE_STATIC_STD_LIBS option if it is enabled
if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4") if(SFML_OS_WINDOWS AND SFML_COMPILER_GCC AND NOT SFML_GCC_VERSION VERSION_LESS "4")
if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM) if(SFML_USE_STATIC_STD_LIBS AND NOT SFML_COMPILER_GCC_TDM)
target_link_libraries(${target} "-static-libgcc" "-static-libstdc++") target_link_libraries(${target} PRIVATE "-static-libgcc" "-static-libstdc++")
elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM) elseif(NOT SFML_USE_STATIC_STD_LIBS AND SFML_COMPILER_GCC_TDM)
target_link_libraries(${target} "-shared-libgcc" "-shared-libstdc++") target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++")
endif() endif()
endif() endif()
@ -17,7 +17,7 @@ function(sfml_set_stdlib target)
set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++")
else() else()
target_compile_options(${target} PRIVATE "-stdlib=libc++") target_compile_options(${target} PRIVATE "-stdlib=libc++")
target_link_libraries(${target} "-stdlib=libc++") target_link_libraries(${target} PRIVATE "-stdlib=libc++")
endif() endif()
endif() endif()
endfunction() endfunction()
@ -25,15 +25,21 @@ endfunction()
# add a new target which is a SFML library # add a new target which is a SFML library
# ex: sfml_add_library(sfml-graphics # ex: sfml_add_library(sfml-graphics
# SOURCES sprite.cpp image.cpp ... # SOURCES sprite.cpp image.cpp ...
# DEPENDS sfml-window sfml-system # [STATIC]) # Always create a static library and ignore BUILD_SHARED_LIBS
# EXTERNAL_LIBS opengl freetype ...)
macro(sfml_add_library target) macro(sfml_add_library target)
# parse the arguments # parse the arguments
cmake_parse_arguments(THIS "" "" "SOURCES;DEPENDS;EXTERNAL_LIBS" ${ARGN}) cmake_parse_arguments(THIS "STATIC" "" "SOURCES" ${ARGN})
if (NOT "${THIS_UNPARSED_ARGUMENTS}" STREQUAL "")
message(FATAL_ERROR "Extra unparsed arguments when calling sfml_add_library: ${THIS_UNPARSED_ARGUMENTS}")
endif()
# create the target # create the target
if (THIS_STATIC)
add_library(${target} STATIC ${THIS_SOURCES})
else()
add_library(${target} ${THIS_SOURCES}) add_library(${target} ${THIS_SOURCES})
endif()
# define the export symbol of the module # define the export symbol of the module
string(REPLACE "-" "_" NAME_UPPER "${target}") string(REPLACE "-" "_" NAME_UPPER "${target}")
@ -41,7 +47,7 @@ macro(sfml_add_library target)
set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS) set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS)
# adjust the output file prefix/suffix to match our conventions # adjust the output file prefix/suffix to match our conventions
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS AND NOT THIS_STATIC)
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
# include the major version number in Windows shared library names (but not import library names) # include the major version number in Windows shared library names (but not import library names)
set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d) set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d)
@ -84,7 +90,7 @@ macro(sfml_add_library target)
set(SFML_PDB_POSTFIX "") set(SFML_PDB_POSTFIX "")
endif() endif()
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS AND NOT THIS_STATIC)
# DLLs export debug symbols in the linker PDB (the compiler PDB is an intermediate file) # DLLs export debug symbols in the linker PDB (the compiler PDB is an intermediate file)
set_target_properties(${target} PROPERTIES set_target_properties(${target} PROPERTIES
PDB_NAME "${target}${SFML_PDB_POSTFIX}" PDB_NAME "${target}${SFML_PDB_POSTFIX}"
@ -103,13 +109,8 @@ macro(sfml_add_library target)
set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden) set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden)
endif() endif()
# link the target to its SFML dependencies
if(THIS_DEPENDS)
target_link_libraries(${target} ${THIS_DEPENDS})
endif()
# build frameworks or dylibs # build frameworks or dylibs
if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS) if(SFML_OS_MACOSX AND BUILD_SHARED_LIBS AND NOT THIS_STATIC)
if(SFML_BUILD_FRAMEWORKS) if(SFML_BUILD_FRAMEWORKS)
# adapt target to build frameworks instead of dylibs # adapt target to build frameworks instead of dylibs
set_target_properties(${target} PROPERTIES set_target_properties(${target} PROPERTIES
@ -151,24 +152,36 @@ macro(sfml_add_library target)
endif() endif()
endif() endif()
# link the target to its external dependencies
if(THIS_EXTERNAL_LIBS)
target_link_libraries(${target} ${THIS_EXTERNAL_LIBS})
endif()
# add the install rule # add the install rule
install(TARGETS ${target} install(TARGETS ${target} EXPORT SFMLConfigExport
RUNTIME DESTINATION bin COMPONENT bin RUNTIME DESTINATION bin COMPONENT bin
LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin
ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel
FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin) FRAMEWORK DESTINATION "." COMPONENT bin)
# add <project>/include as public include directory
target_include_directories(${target}
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
PRIVATE ${PROJECT_SOURCE_DIR}/src)
if (SFML_BUILD_FRAMEWORKS)
target_include_directories(${target} INTERFACE $<INSTALL_INTERFACE:SFML.framework>)
else()
target_include_directories(${target} INTERFACE $<INSTALL_INTERFACE:include>)
endif()
# define SFML_STATIC if the build type is not set to 'shared'
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(${target} PUBLIC "SFML_STATIC")
endif()
endmacro() endmacro()
# add a new target which is a SFML example # add a new target which is a SFML example
# ex: sfml_add_example(ftp # ex: sfml_add_example(ftp
# SOURCES ftp.cpp ... # SOURCES ftp.cpp ...
# BUNDLE_RESOURCES MainMenu.nib ... # Files to be added in target but not installed next to the executable # BUNDLE_RESOURCES MainMenu.nib ... # Files to be added in target but not installed next to the executable
# DEPENDS sfml-network sfml-system # DEPENDS sfml-network
# RESOURCES_DIR resources) # A directory to install next to the executable and sources # RESOURCES_DIR resources) # A directory to install next to the executable and sources
macro(sfml_add_example target) macro(sfml_add_example target)
@ -187,7 +200,7 @@ macro(sfml_add_example target)
# create the target # create the target
if(THIS_GUI_APP AND SFML_OS_WINDOWS AND NOT DEFINED CMAKE_CONFIGURATION_TYPES AND ${CMAKE_BUILD_TYPE} STREQUAL "Release") if(THIS_GUI_APP AND SFML_OS_WINDOWS AND NOT DEFINED CMAKE_CONFIGURATION_TYPES AND ${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_executable(${target} WIN32 ${target_input}) add_executable(${target} WIN32 ${target_input})
target_link_libraries(${target} sfml-main) target_link_libraries(${target} PRIVATE sfml-main)
else() else()
add_executable(${target} ${target_input}) add_executable(${target} ${target_input})
endif() endif()
@ -203,17 +216,17 @@ macro(sfml_add_example target)
# link the target to its SFML dependencies # link the target to its SFML dependencies
if(THIS_DEPENDS) if(THIS_DEPENDS)
target_link_libraries(${target} ${THIS_DEPENDS}) target_link_libraries(${target} PRIVATE ${THIS_DEPENDS})
endif() endif()
# add the install rule # add the install rule
install(TARGETS ${target} install(TARGETS ${target}
RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples RUNTIME DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples
BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples) BUNDLE DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples)
# install the example's source code # install the example's source code
install(FILES ${THIS_SOURCES} install(FILES ${THIS_SOURCES}
DESTINATION ${INSTALL_MISC_DIR}/examples/${target} DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target}
COMPONENT examples) COMPONENT examples)
if (THIS_RESOURCES_DIR) if (THIS_RESOURCES_DIR)
@ -224,8 +237,55 @@ macro(sfml_add_example target)
message(FATAL_ERROR "Given resources directory to install does not exist: ${THIS_RESOURCES_DIR}") message(FATAL_ERROR "Given resources directory to install does not exist: ${THIS_RESOURCES_DIR}")
endif() endif()
install(DIRECTORY ${THIS_RESOURCES_DIR} install(DIRECTORY ${THIS_RESOURCES_DIR}
DESTINATION ${INSTALL_MISC_DIR}/examples/${target} DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target}
COMPONENT examples) COMPONENT examples)
endif() endif()
endmacro() endmacro()
# Find the requested package and make an INTERFACE library from it
# Usage: sfml_find_package(wanted_target_name
# [INCLUDE "OPENGL_INCLUDE_DIR"]
# [LINK "OPENGL_gl_LIBRARY"])
function(sfml_find_package)
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
list(GET ARGN 0 target)
list(REMOVE_AT ARGN 0)
if (TARGET ${target})
message(FATAL_ERROR "Target '${target}' is already defined")
endif()
cmake_parse_arguments(THIS "" "" "INCLUDE;LINK" ${ARGN})
if (THIS_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unknown arguments when calling sfml_import_library: ${THIS_UNPARSED_ARGUMENTS}")
endif()
if (SFML_OS_IOS)
find_host_package(${target} REQUIRED)
else()
find_package(${target} REQUIRED)
endif()
add_library(${target} INTERFACE)
if (THIS_INCLUDE)
foreach(include_dir IN LISTS "${THIS_INCLUDE}")
if (NOT include_dir)
message(FATAL_ERROR "No path given for include dir ${THIS_INCLUDE}")
endif()
target_include_directories(${target} INTERFACE "$<BUILD_INTERFACE:${include_dir}>")
endforeach()
endif()
if (THIS_LINK)
foreach(link_item IN LISTS ${THIS_LINK})
if (NOT link_item)
message(FATAL_ERROR "Missing item in ${THIS_LINK}")
endif()
target_link_libraries(${target} INTERFACE "$<BUILD_INTERFACE:${link_item}>")
endforeach()
endif()
endfunction()

View File

@ -50,3 +50,4 @@ ELSE (UDEV_FOUND)
ENDIF (UDev_FIND_REQUIRED) ENDIF (UDev_FIND_REQUIRED)
ENDIF (UDEV_FOUND) ENDIF (UDEV_FOUND)
mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBRARIES)

View File

@ -810,20 +810,16 @@ else()
endif() endif()
set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE ) set( ANDROID_NATIVE_API_LEVEL "${ANDROID_NATIVE_API_LEVEL}" CACHE STRING "Android API level for native code" FORCE )
set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} ) set( CMAKE_ANDROID_API ${ANDROID_NATIVE_API_LEVEL} )
if( CMAKE_VERSION VERSION_GREATER "2.8" )
list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS )
set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} )
endif() endif()
endif()
unset( __levelIdx ) unset( __levelIdx )
# remember target ABI # remember target ABI
set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE ) set( ANDROID_ABI "${ANDROID_ABI}" CACHE STRING "The target ABI for Android. If arm, then armeabi-v7a is recommended for hardware floating point." FORCE )
if( CMAKE_VERSION VERSION_GREATER "2.8" )
list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} )
set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} )
endif()
# runtime choice (STL, rtti, exceptions) # runtime choice (STL, rtti, exceptions)
@ -1137,9 +1133,6 @@ if( NOT CMAKE_C_COMPILER )
endif() endif()
set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" ) set( _CMAKE_TOOLCHAIN_PREFIX "${ANDROID_TOOLCHAIN_MACHINE_NAME}-" )
if( CMAKE_VERSION VERSION_LESS 2.8.5 )
set( CMAKE_ASM_COMPILER_ARG1 "-c" )
endif()
if( APPLE ) if( APPLE )
find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool ) find_program( CMAKE_INSTALL_NAME_TOOL NAMES install_name_tool )
if( NOT CMAKE_INSTALL_NAME_TOOL ) if( NOT CMAKE_INSTALL_NAME_TOOL )
@ -1443,7 +1436,7 @@ if( MIPS AND BUILD_WITH_ANDROID_NDK AND ANDROID_NDK_RELEASE STREQUAL "r8" )
endif() endif()
# pie/pic # pie/pic
if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE) AND (CMAKE_VERSION VERSION_GREATER 2.8.8) ) if( NOT (ANDROID_NATIVE_API_LEVEL LESS 16) AND (NOT DEFINED ANDROID_APP_PIE OR ANDROID_APP_PIE))
set( CMAKE_POSITION_INDEPENDENT_CODE TRUE ) set( CMAKE_POSITION_INDEPENDENT_CODE TRUE )
set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie") set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie")
else() else()

View File

@ -53,10 +53,10 @@ add_custom_target(doc ALL
# setup install rules # setup install rules
install(DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html install(DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html
DESTINATION ${INSTALL_MISC_DIR}/doc DESTINATION ${SFML_MISC_INSTALL_PREFIX}/doc
COMPONENT doc) COMPONENT doc)
if(DOXYGEN_HHC_PROGRAM) if(DOXYGEN_HHC_PROGRAM)
install(FILES ${DOXYGEN_OUTPUT_DIR}/sfml.chm install(FILES ${DOXYGEN_OUTPUT_DIR}/sfml.chm
DESTINATION ${INSTALL_MISC_DIR}/doc DESTINATION ${SFML_MISC_INSTALL_PREFIX}/doc
COMPONENT doc) COMPONENT doc)
endif() endif()

View File

@ -4,13 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11)
# all source files # all source files
set(SRC ${SRCROOT}/X11.cpp) set(SRC ${SRCROOT}/X11.cpp)
# find OpenGL and X11
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
find_package(X11 REQUIRED)
include_directories(${X11_INCLUDE_DIR})
# define the X11 target # define the X11 target
sfml_add_example(X11 GUI_APP sfml_add_example(X11Example GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-window sfml-system ${OPENGL_LIBRARIES} ${X11_LIBRARIES}) DEPENDS sfml-window OpenGL X11)

View File

@ -58,4 +58,4 @@ sfml_add_example(cocoa
set_target_properties(cocoa PROPERTIES set_target_properties(cocoa PROPERTIES
MACOSX_BUNDLE TRUE MACOSX_BUNDLE TRUE
MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist) MACOSX_BUNDLE_INFO_PLIST ${SRCROOT}/resources/Cocoa-Info.plist)
target_link_libraries(cocoa "-framework Cocoa -framework Foundation") target_link_libraries(cocoa PRIVATE "-framework Cocoa" "-framework Foundation" sfml-graphics)

View File

@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/Ftp.cpp)
# define the ftp target # define the ftp target
sfml_add_example(ftp sfml_add_example(ftp
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-network sfml-system) DEPENDS sfml-network)

View File

@ -4,13 +4,8 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl)
# all source files # all source files
set(SRC ${SRCROOT}/OpenGL.cpp) set(SRC ${SRCROOT}/OpenGL.cpp)
# find OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
# define the opengl target # define the opengl target
sfml_add_example(opengl GUI_APP sfml_add_example(opengl GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-graphics sfml-window sfml-system ${ADDITIONAL_LIBRARIES} DEPENDS sfml-graphics OpenGL
RESOURCES_DIR resources) RESOURCES_DIR resources)

View File

@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Pong.cpp)
# define the pong target # define the pong target
sfml_add_example(pong GUI_APP sfml_add_example(pong GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-audio sfml-graphics sfml-window sfml-system DEPENDS sfml-audio sfml-graphics
RESOURCES_DIR resources) RESOURCES_DIR resources)

View File

@ -9,5 +9,5 @@ set(SRC
# define the shader target # define the shader target
sfml_add_example(shader GUI_APP sfml_add_example(shader GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-graphics sfml-window sfml-system DEPENDS sfml-graphics
RESOURCES_DIR resources) RESOURCES_DIR resources)

View File

@ -9,4 +9,4 @@ set(SRC ${SRCROOT}/Sockets.cpp
# define the sockets target # define the sockets target
sfml_add_example(sockets sfml_add_example(sockets
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-network sfml-system) DEPENDS sfml-network)

View File

@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Sound.cpp)
# define the sound target # define the sound target
sfml_add_example(sound sfml_add_example(sound
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-audio sfml-system DEPENDS sfml-audio
RESOURCES_DIR resources) RESOURCES_DIR resources)

View File

@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/SoundCapture.cpp)
# define the sound-capture target # define the sound-capture target
sfml_add_example(sound-capture sfml_add_example(sound-capture
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-audio sfml-system) DEPENDS sfml-audio)

View File

@ -9,4 +9,4 @@ set(SRC ${SRCROOT}/VoIP.cpp
# define the voip target # define the voip target
sfml_add_example(voip sfml_add_example(voip
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-audio sfml-network sfml-system) DEPENDS sfml-audio sfml-network)

View File

@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Win32.cpp)
# define the win32 target # define the win32 target
sfml_add_example(win32 GUI_APP sfml_add_example(win32 GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-graphics sfml-window sfml-system DEPENDS sfml-graphics
RESOURCES_DIR resources) RESOURCES_DIR resources)

View File

@ -4,12 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/window)
# all source files # all source files
set(SRC ${SRCROOT}/Window.cpp) set(SRC ${SRCROOT}/Window.cpp)
# find OpenGL
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
set(ADDITIONAL_LIBRARIES ${OPENGL_LIBRARIES})
# define the window target # define the window target
sfml_add_example(window GUI_APP sfml_add_example(window GUI_APP
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-window sfml-system ${ADDITIONAL_LIBRARIES}) DEPENDS sfml-window OpenGL)

View File

@ -66,35 +66,25 @@ elseif(SFML_OS_ANDROID)
endif() endif()
# find external libraries # find external libraries
if(SFML_OS_IOS) sfml_find_package(OpenAL INCLUDE "OPENAL_INCLUDE_DIR" LINK "OPENAL_LIBRARY")
find_host_package(OpenAL REQUIRED) sfml_find_package(Vorbis INCLUDE "VORBIS_INCLUDE_DIRS" LINK "VORBIS_LIBRARIES")
find_host_package(Vorbis REQUIRED) sfml_find_package(FLAC INCLUDE "FLAC_INCLUDE_DIR" LINK "FLAC_LIBRARY")
find_host_package(FLAC REQUIRED)
else()
find_package(OpenAL REQUIRED)
find_package(Vorbis REQUIRED)
find_package(FLAC REQUIRED)
endif()
include_directories(${OPENAL_INCLUDE_DIR}) # avoids warnings in vorbisfile.h
include_directories(${VORBIS_INCLUDE_DIRS}) target_compile_definitions(Vorbis INTERFACE "OV_EXCLUDE_STATIC_CALLBACKS")
include_directories(${FLAC_INCLUDE_DIR}) target_compile_definitions(FLAC INTERFACE "FLAC__NO_DLL")
add_definitions(-DOV_EXCLUDE_STATIC_CALLBACKS) # avoids warnings in vorbisfile.h
add_definitions(-DFLAC__NO_DLL)
# build the list of external libraries to link
if(SFML_OS_IOS)
list(APPEND AUDIO_EXT_LIBS "-framework OpenAL")
else()
list(APPEND AUDIO_EXT_LIBS ${OPENAL_LIBRARY})
endif()
if(SFML_OS_ANDROID)
list(APPEND AUDIO_EXT_LIBS android OpenSLES)
endif()
list(APPEND AUDIO_EXT_LIBS ${VORBIS_LIBRARIES} ${FLAC_LIBRARY})
# define the sfml-audio target # define the sfml-audio target
sfml_add_library(sfml-audio sfml_add_library(sfml-audio
SOURCES ${SRC} ${CODECS_SRC} SOURCES ${SRC} ${CODECS_SRC})
DEPENDS sfml-system
EXTERNAL_LIBS ${AUDIO_EXT_LIBS}) # setup dependencies
target_link_libraries(sfml-audio PRIVATE OpenAL)
if(SFML_OS_ANDROID)
target_link_libraries(sfml-audio PRIVATE android OpenSLES)
endif()
target_link_libraries(sfml-audio
PUBLIC sfml-system
PRIVATE Vorbis FLAC)

View File

@ -39,9 +39,6 @@ elseif(SFML_OS_ANDROID)
set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI}") set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${PROJECT_SOURCE_DIR}/extlibs/libs-android/${CMAKE_ANDROID_ARCH_ABI}")
endif() endif()
# add the SFML sources path
include_directories(${PROJECT_SOURCE_DIR}/src)
# define the path of our additional CMake modules # define the path of our additional CMake modules
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")

View File

@ -88,8 +88,16 @@ set(RENDER_TEXTURE_SRC
) )
source_group("render texture" FILES ${RENDER_TEXTURE_SRC}) source_group("render texture" FILES ${RENDER_TEXTURE_SRC})
# define the sfml-graphics target
sfml_add_library(sfml-graphics
SOURCES ${SRC} ${DRAWABLES_SRC} ${RENDER_TEXTURE_SRC} ${STB_SRC})
# setup dependencies
target_link_libraries(sfml-graphics PUBLIC sfml-window)
# stb_image sources # stb_image sources
include_directories("${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image") target_include_directories(sfml-graphics PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/stb_image")
# let CMake know about our additional graphics libraries paths # let CMake know about our additional graphics libraries paths
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
@ -104,53 +112,36 @@ elseif(SFML_OS_ANDROID)
endif() endif()
# find external libraries # find external libraries
if(NOT SFML_OPENGL_ES) if(SFML_OPENGL_ES)
find_package(OpenGL REQUIRED)
if(SFML_OS_LINUX) if(SFML_OS_LINUX)
find_package(X11 REQUIRED) sfml_find_package(EGL INCLUDE "EGL_INCLUDE_DIR" LINK "EGL_LIBRARY")
sfml_find_package(GLES INCLUDE "GLES_INCLUDE_DIR" LINK "GLES_LIBRARY")
target_link_libraries(sfml-graphics PRIVATE EGL GLES)
elseif(SFML_OS_IOS)
target_link_libraries(sfml-graphics PRIVATE "-framework OpenGLES")
endif() endif()
include_directories(${FREETYPE_INCLUDE_DIRS} ${OPENGL_INCLUDE_DIR})
endif()
if(SFML_OPENGL_ES AND SFML_OS_LINUX)
find_package(EGL REQUIRED)
find_package(GLES REQUIRED)
include_directories(${EGL_INCLUDE_DIR} ${GLES_INCLUDE_DIR})
endif()
if(SFML_OS_IOS)
find_host_package(Freetype REQUIRED)
else() else()
find_package(Freetype REQUIRED) # Target OpenGL already defined for Window component so no sfml_find_package() here
endif() target_link_libraries(sfml-graphics PRIVATE OpenGL)
include_directories(${FREETYPE_INCLUDE_DIRS})
# build the list of external libraries to link
if(NOT SFML_OPENGL_ES)
list(APPEND GRAPHICS_EXT_LIBS ${OPENGL_gl_LIBRARY})
if(SFML_OS_LINUX) if(SFML_OS_LINUX)
list(APPEND GRAPHICS_EXT_LIBS ${X11_LIBRARIES}) # Target X11 already defined for Window component so no sfml_find_package() here
target_link_libraries(sfml-graphics PRIVATE X11)
endif() endif()
endif() endif()
if(SFML_OPENGL_ES AND SFML_OS_LINUX)
list(APPEND GRAPHICS_EXT_LIBS ${EGL_LIBRARY} ${GLES_LIBRARY}) if(SFML_OS_ANDROID)
target_link_libraries(sfml-graphics PRIVATE z EGL GLESv1_CM)
endif() endif()
if(SFML_OS_IOS)
list(APPEND GRAPHICS_EXT_LIBS "-framework OpenGLES") sfml_find_package(Freetype INCLUDE "FREETYPE_INCLUDE_DIRS" LINK "FREETYPE_LIBRARY")
elseif(SFML_OS_ANDROID) target_link_libraries(sfml-graphics PRIVATE Freetype)
list(APPEND GRAPHICS_EXT_LIBS z)
endif()
list(APPEND GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY})
# add preprocessor symbols # add preprocessor symbols
add_definitions(-DSTBI_FAILURE_USERMSG) target_compile_definitions(sfml-graphics PRIVATE "STBI_FAILURE_USERMSG")
# ImageLoader.cpp must be compiled with the -fno-strict-aliasing # ImageLoader.cpp must be compiled with the -fno-strict-aliasing
# when gcc is used; otherwise saving PNGs may crash in stb_image_write # when gcc is used; otherwise saving PNGs may crash in stb_image_write
if(SFML_COMPILER_GCC) if(SFML_COMPILER_GCC)
set_source_files_properties(${SRCROOT}/ImageLoader.cpp PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) set_source_files_properties(${SRCROOT}/ImageLoader.cpp PROPERTIES COMPILE_FLAGS -fno-strict-aliasing)
endif() endif()
# define the sfml-graphics target
sfml_add_library(sfml-graphics
SOURCES ${SRC} ${DRAWABLES_SRC} ${RENDER_TEXTURE_SRC} ${STB_SRC}
DEPENDS sfml-window sfml-system
EXTERNAL_LIBS ${GRAPHICS_EXT_LIBS})

View File

@ -12,26 +12,20 @@ elseif(SFML_OS_ANDROID)
else() else()
return() return()
endif() endif()
source_group("" FILES ${SRC})
# define the sfml-main target # define the sfml-main target
add_library(sfml-main STATIC ${SRC}) sfml_add_library(sfml-main STATIC SOURCES ${SRC})
# set the debug suffix # overwrite sfml-main suffix for backward compatibility with FindSFML.cmake
set_target_properties(sfml-main PROPERTIES DEBUG_POSTFIX -d) set_target_properties(sfml-main PROPERTIES
DEBUG_POSTFIX -d
# insert the major version number in the output filename RELEASE_POSTFIX ""
set_target_properties(sfml-main PROPERTIES OUTPUT_NAME "sfml-main") MINSIZEREL_POSTFIX ""
RELWITHDEBINFO_POSTFIX "")
# set the target's folder (for IDEs that support it, e.g. Visual Studio)
set_target_properties(sfml-main PROPERTIES FOLDER "SFML")
# setup the install rule
install(TARGETS sfml-main ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel)
# because of a current limitation on Android (which prevents one library # because of a current limitation on Android (which prevents one library
# from depending on shared libraries), we need a boostrap activity which # from depending on shared libraries), we need a boostrap activity which
# will load our shared libraries manually # will load our shared libraries manually
if(SFML_OS_ANDROID) if(SFML_OS_ANDROID)
sfml_add_library(sfml-activity SOURCES ${PROJECT_SOURCE_DIR}/src/SFML/Main/SFMLActivity.cpp) sfml_add_library(sfml-activity SOURCES ${SRCROOT}/SFMLActivity.cpp)
endif() endif()

View File

@ -44,14 +44,12 @@ endif()
source_group("" FILES ${SRC}) source_group("" FILES ${SRC})
# build the list of external libraries to link
set(NETWORK_EXT_LIBS)
if(SFML_OS_WINDOWS)
set(NETWORK_EXT_LIBS ${NETWORK_EXT_LIBS} ws2_32)
endif()
# define the sfml-network target # define the sfml-network target
sfml_add_library(sfml-network sfml_add_library(sfml-network
SOURCES ${SRC} SOURCES ${SRC})
DEPENDS sfml-system
EXTERNAL_LIBS ${NETWORK_EXT_LIBS}) # setup dependencies
target_link_libraries(sfml-network PUBLIC sfml-system)
if(SFML_OS_WINDOWS)
target_link_libraries(sfml-network PRIVATE ws2_32)
endif()

View File

@ -85,21 +85,18 @@ else()
source_group("unix" FILES ${PLATFORM_SRC}) source_group("unix" FILES ${PLATFORM_SRC})
endif() endif()
# build the list of external libraries to link
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
list(APPEND SYSTEM_EXT_LIBS pthread)
endif()
if(SFML_OS_LINUX)
list(APPEND SYSTEM_EXT_LIBS rt)
endif()
if(SFML_OS_WINDOWS)
list(APPEND SYSTEM_EXT_LIBS winmm)
endif()
if(SFML_OS_ANDROID)
list(APPEND SYSTEM_EXT_LIBS android log)
endif()
# define the sfml-system target # define the sfml-system target
sfml_add_library(sfml-system sfml_add_library(sfml-system
SOURCES ${SRC} ${PLATFORM_SRC} SOURCES ${SRC} ${PLATFORM_SRC})
EXTERNAL_LIBS ${SYSTEM_EXT_LIBS})
# setup dependencies
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX)
target_link_libraries(sfml-system PRIVATE pthread)
endif()
if(SFML_OS_LINUX)
target_link_libraries(sfml-system PRIVATE rt)
elseif(SFML_OS_WINDOWS)
target_link_libraries(sfml-system PRIVATE winmm)
elseif(SFML_OS_ANDROID)
target_link_libraries(sfml-system PRIVATE android log)
endif()

View File

@ -218,70 +218,53 @@ elseif(SFML_OS_ANDROID)
source_group("android" FILES ${PLATFORM_SRC}) source_group("android" FILES ${PLATFORM_SRC})
endif() endif()
# find external libraries # define the sfml-window target
sfml_add_library(sfml-window
SOURCES ${SRC} ${PLATFORM_SRC})
target_link_libraries(sfml-window PUBLIC sfml-system)
# find and setup usage for external libraries
if(SFML_OS_LINUX OR SFML_OS_FREEBSD) if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
find_package(X11 REQUIRED) sfml_find_package(X11 INCLUDE "X11_INCLUDE_DIR" LINK "X11_X11_LIB" "X11_Xrandr_LIB")
if(NOT X11_FOUND) target_link_libraries(sfml-window PRIVATE X11)
message(FATAL_ERROR "X11 library not found")
endif() endif()
if(NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "Xrandr library not found") if(SFML_OPENGL_ES)
if(SFML_OS_IOS)
target_link_libraries(sfml-window PRIVATE "-framework OpenGLES")
elseif(SFML_OS_ANDROID)
target_link_libraries(sfml-window PRIVATE EGL GLESv1_CM)
endif() endif()
include_directories(${X11_INCLUDE_DIR}) else()
endif() sfml_find_package(OpenGL INCLUDE "OPENGL_INCLUDE_DIR" LINK "OPENGL_gl_LIBRARY")
if(NOT SFML_OPENGL_ES) target_link_libraries(sfml-window PRIVATE OpenGL)
find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR})
endif()
if(SFML_OPENGL_ES AND SFML_OS_LINUX)
find_package(EGL REQUIRED)
find_package(GLES REQUIRED)
include_directories(${EGL_INCLUDE_DIR} ${GLES_INCLUDE_DIR})
endif()
if(SFML_OS_LINUX)
find_package(UDev REQUIRED)
if(NOT UDEV_FOUND)
message(FATAL_ERROR "udev library not found")
endif()
include_directories(${UDEV_INCLUDE_DIR})
endif() endif()
if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC) if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC)
include(CheckIncludeFile) include(CheckIncludeFile)
check_include_file(dinput.h DINPUT_H_FOUND) check_include_file(dinput.h DINPUT_H_FOUND)
if(NOT DINPUT_H_FOUND) if(NOT DINPUT_H_FOUND)
include_directories("${PROJECT_SOURCE_DIR}/extlibs/headers/mingw") target_include_directories(sfml-window PRIVATE "${PROJECT_SOURCE_DIR}/extlibs/headers/mingw")
endif() endif()
endif() endif()
if(SFML_OPENGL_ES AND SFML_OS_LINUX)
# build the list of external libraries to link sfml_find_package(EGL INCLUDE "EGL_INCLUDE_DIR" LINK "EGL_LIBRARY")
if(SFML_OS_WINDOWS) sfml_find_package(GLES INCLUDE "GLES_INCLUDE_DIR" LINK "GLES_LIBRARY")
list(APPEND WINDOW_EXT_LIBS winmm gdi32) target_link_libraries(sfml-window PRIVATE EGL GLES)
elseif(SFML_OS_LINUX)
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES})
elseif(SFML_OS_FREEBSD)
list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} usbhid)
elseif(SFML_OS_MACOSX)
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon")
elseif(SFML_OS_IOS)
list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework CoreMotion")
elseif(SFML_OS_ANDROID)
list(APPEND WINDOW_EXT_LIBS android)
endif() endif()
if(SFML_OPENGL_ES)
if(SFML_OS_LINUX) if(SFML_OS_LINUX)
list(APPEND WINDOW_EXT_LIBS ${EGL_LIBRARY} ${GLES_LIBRARY}) sfml_find_package(UDev INCLUDE "UDEV_INCLUDE_DIR" LINK "UDEV_LIBRARIES")
target_link_libraries(sfml-window PRIVATE UDev)
elseif(SFML_OS_WINDOWS)
target_link_libraries(sfml-window PRIVATE winmm gdi32)
elseif(SFML_OS_FREEBSD)
target_link_libraries(sfml-window PRIVATE usbhid)
elseif(SFML_OS_MACOSX)
target_link_libraries(sfml-window PRIVATE "-framework Foundation" "-framework AppKit" "-framework IOKit" "-framework Carbon")
elseif(SFML_OS_IOS) elseif(SFML_OS_IOS)
list(APPEND WINDOW_EXT_LIBS "-framework OpenGLES") target_link_libraries(sfml-window PRIVATE "-framework Foundation" "-framework UIKit" "-framework CoreGraphics" "-framework QuartzCore" "-framework CoreMotion")
elseif(SFML_OS_ANDROID) elseif(SFML_OS_ANDROID)
list(APPEND WINDOW_EXT_LIBS EGL GLESv1_CM) target_link_libraries(sfml-window PRIVATE android)
endif() endif()
else()
list(APPEND WINDOW_EXT_LIBS ${OPENGL_gl_LIBRARY})
endif()
# define the sfml-window target
sfml_add_library(sfml-window
SOURCES ${SRC} ${PLATFORM_SRC}
DEPENDS sfml-system
EXTERNAL_LIBS ${WINDOW_EXT_LIBS})

View File

@ -146,7 +146,8 @@ subject to the following restrictions:
# If you're using static libraries (which is not recommended) you should remove this script from your project. # If you're using static libraries (which is not recommended) you should remove this script from your project.
# SETTINGS # SETTINGS
CMAKE_INSTALL_FRAMEWORK_PREFIX="@CMAKE_INSTALL_FRAMEWORK_PREFIX@" SFML_DEPENDENCIES_INSTALL_PREFIX="@SFML_DEPENDENCIES_INSTALL_PREFIX@"
CMAKE_INSTALL_FRAMEWORK_PREFIX="@CMAKE_INSTALL_PREFIX@"
CMAKE_INSTALL_LIB_PREFIX="@CMAKE_INSTALL_PREFIX@/lib" CMAKE_INSTALL_LIB_PREFIX="@CMAKE_INSTALL_PREFIX@/lib"
FRAMEWORKS_FULL_PATH="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/" FRAMEWORKS_FULL_PATH="$BUILT_PRODUCTS_DIR/$FRAMEWORKS_FOLDER_PATH/"
@ -231,11 +232,11 @@ require () # $1 is a SFML module like 'system' or 'audio'
# copy "FLAC" "ogg" "vorbis" "vorbisenc" "vorbisfile" "OpenAL" frameworks too # copy "FLAC" "ogg" "vorbis" "vorbisenc" "vorbisfile" "OpenAL" frameworks too
for f in "FLAC" "ogg" "vorbis" "vorbisenc" "vorbisfile" "OpenAL" for f in "FLAC" "ogg" "vorbis" "vorbisenc" "vorbisfile" "OpenAL"
do do
copy "$CMAKE_INSTALL_FRAMEWORK_PREFIX/$f.framework" "$dest/$f.framework" copy "$SFML_DEPENDENCIES_INSTALL_PREFIX/$f.framework" "$dest/$f.framework"
done done
elif [ "$1" = "graphics" ] elif [ "$1" = "graphics" ]
then then
copy "$CMAKE_INSTALL_FRAMEWORK_PREFIX/freetype.framework" "$dest/freetype.framework" copy "$SFML_DEPENDENCIES_INSTALL_PREFIX/freetype.framework" "$dest/freetype.framework"
fi fi
fi fi
} }