From ee08e18726788e4855218fa27319b2313b185d0f Mon Sep 17 00:00:00 2001 From: Ceylo Date: Tue, 20 Mar 2018 19:46:57 +0100 Subject: [PATCH] Modernize CMake files --- CMakeLists.txt | 72 ++++++----- cmake/Config.cmake | 11 +- cmake/Macros.cmake | 118 +++++++++++++----- cmake/Modules/FindUDev.cmake | 1 + cmake/toolchains/android.toolchain.cmake | 17 +-- doc/CMakeLists.txt | 4 +- examples/X11/CMakeLists.txt | 10 +- examples/cocoa/CMakeLists.txt | 2 +- examples/ftp/CMakeLists.txt | 2 +- examples/opengl/CMakeLists.txt | 7 +- examples/pong/CMakeLists.txt | 2 +- examples/shader/CMakeLists.txt | 2 +- examples/sockets/CMakeLists.txt | 2 +- examples/sound/CMakeLists.txt | 2 +- examples/sound_capture/CMakeLists.txt | 2 +- examples/voip/CMakeLists.txt | 2 +- examples/win32/CMakeLists.txt | 2 +- examples/window/CMakeLists.txt | 7 +- src/SFML/Audio/CMakeLists.txt | 46 +++---- src/SFML/CMakeLists.txt | 3 - src/SFML/Graphics/CMakeLists.txt | 61 ++++----- src/SFML/Main/CMakeLists.txt | 22 ++-- src/SFML/Network/CMakeLists.txt | 16 ++- src/SFML/System/CMakeLists.txt | 29 ++--- src/SFML/Window/CMakeLists.txt | 85 +++++-------- .../SFML App.xctemplate/TemplateInfo.plist.in | 7 +- 26 files changed, 259 insertions(+), 275 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 47afd9e22..8fc120fb9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Android") cmake_minimum_required(VERSION 3.7.2) else() - cmake_minimum_required(VERSION 2.8.3) + cmake_minimum_required(VERSION 3.0.2) endif() # 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) # Suppress Mac OS X RPATH warnings and adopt new related behaviors -if(NOT CMAKE_VERSION VERSION_LESS 3.0) - cmake_policy(SET CMP0042 NEW) -endif() +cmake_policy(SET CMP0042 NEW) if (NOT CMAKE_VERSION VERSION_LESS 3.9) cmake_policy(SET CMP0068 NEW) endif() @@ -57,9 +55,6 @@ set(VERSION_MAJOR 2) set(VERSION_MINOR 4) 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) 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") @@ -97,11 +92,14 @@ if(SFML_OS_MACOSX) # 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 let the user specify a custom directory for frameworks installation (SFML, FLAC, ...) - sfml_set_option(CMAKE_INSTALL_FRAMEWORK_PREFIX "/Library/Frameworks" STRING "Frameworks installation directory") + # add an option to let the user specify a custom directory for external frameworks installation + 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 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() # Android options @@ -141,10 +139,20 @@ if(SFML_OS_ANDROID) set(CMAKE_CXX_CREATE_SHARED_LIBRARY_WITHOUT_STL " -o ") endif() -# define SFML_STATIC if the build type is not set to 'shared' -if(NOT BUILD_SHARED_LIBS) - add_definitions(-DSFML_STATIC) +# Install directories +# For miscellaneous files +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() +# 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 if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW) @@ -408,15 +416,12 @@ else() # install rule install(TARGETS SFML - FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} + FRAMEWORK DESTINATION "." COMPONENT devel) endif() -install(FILES license.md DESTINATION ${INSTALL_MISC_DIR}) -install(FILES readme.md DESTINATION ${INSTALL_MISC_DIR}) -if(NOT SFML_OS_ANDROID) - install(FILES cmake/Modules/FindSFML.cmake DESTINATION ${INSTALL_MISC_DIR}/cmake/Modules) -endif() +install(FILES license.md DESTINATION ${SFML_MISC_INSTALL_PREFIX}) +install(FILES readme.md DESTINATION ${SFML_MISC_INSTALL_PREFIX}) # install 3rd-party libraries and tools if(SFML_OS_WINDOWS) @@ -424,58 +429,57 @@ if(SFML_OS_WINDOWS) if(NOT SFML_USE_SYSTEM_DEPS) # install the binaries of SFML dependencies 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) - install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION lib) + install(DIRECTORY extlibs/libs-msvc/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib) 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() - install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION lib) + install(DIRECTORY extlibs/libs-mingw/x86/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib) endif() 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) - install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION lib) + install(DIRECTORY extlibs/libs-msvc/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib) 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() - install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION lib) + install(DIRECTORY extlibs/libs-mingw/x64/ DESTINATION ${SFML_DEPENDENCIES_INSTALL_PREFIX}/lib) endif() endif() endif() elseif(SFML_OS_MACOSX) - # install extlibs dependencies only when used if(SFML_BUILD_GRAPHICS) 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() if(SFML_BUILD_AUDIO) 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() 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() 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() 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() 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() 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() diff --git a/cmake/Config.cmake b/cmake/Config.cmake index ca841d382..cebf3debb 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -81,7 +81,7 @@ endif() # detect the compiler and its version # Note: on some platforms (OS X), CMAKE_COMPILER_IS_GNUCXX is true # 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, # but there is no other way to detect CLang at the moment set(SFML_COMPILER_CLANG 1) @@ -117,12 +117,3 @@ else() message(FATAL_ERROR "Unsupported compiler") return() 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() diff --git a/cmake/Macros.cmake b/cmake/Macros.cmake index fa2b78b37..62f439e82 100644 --- a/cmake/Macros.cmake +++ b/cmake/Macros.cmake @@ -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 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) - 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) - target_link_libraries(${target} "-shared-libgcc" "-shared-libstdc++") + target_link_libraries(${target} PRIVATE "-shared-libgcc" "-shared-libstdc++") endif() endif() @@ -17,7 +17,7 @@ function(sfml_set_stdlib target) set_property(TARGET ${target} PROPERTY XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY "libc++") else() target_compile_options(${target} PRIVATE "-stdlib=libc++") - target_link_libraries(${target} "-stdlib=libc++") + target_link_libraries(${target} PRIVATE "-stdlib=libc++") endif() endif() endfunction() @@ -25,15 +25,21 @@ endfunction() # add a new target which is a SFML library # ex: sfml_add_library(sfml-graphics # SOURCES sprite.cpp image.cpp ... -# DEPENDS sfml-window sfml-system -# EXTERNAL_LIBS opengl freetype ...) +# [STATIC]) # Always create a static library and ignore BUILD_SHARED_LIBS macro(sfml_add_library target) # 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 - add_library(${target} ${THIS_SOURCES}) + if (THIS_STATIC) + add_library(${target} STATIC ${THIS_SOURCES}) + else() + add_library(${target} ${THIS_SOURCES}) + endif() # define the export symbol of the module string(REPLACE "-" "_" NAME_UPPER "${target}") @@ -41,7 +47,7 @@ macro(sfml_add_library target) set_target_properties(${target} PROPERTIES DEFINE_SYMBOL ${NAME_UPPER}_EXPORTS) # 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) # include the major version number in Windows shared library names (but not import library names) set_target_properties(${target} PROPERTIES DEBUG_POSTFIX -d) @@ -84,7 +90,7 @@ macro(sfml_add_library target) set(SFML_PDB_POSTFIX "") 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) set_target_properties(${target} PROPERTIES PDB_NAME "${target}${SFML_PDB_POSTFIX}" @@ -103,13 +109,8 @@ macro(sfml_add_library target) set_target_properties(${target} PROPERTIES COMPILE_FLAGS -fvisibility=hidden) endif() - # link the target to its SFML dependencies - if(THIS_DEPENDS) - target_link_libraries(${target} ${THIS_DEPENDS}) - endif() - # 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) # adapt target to build frameworks instead of dylibs set_target_properties(${target} PROPERTIES @@ -151,24 +152,36 @@ macro(sfml_add_library target) 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 - install(TARGETS ${target} + install(TARGETS ${target} EXPORT SFMLConfigExport RUNTIME DESTINATION bin COMPONENT bin LIBRARY DESTINATION lib${LIB_SUFFIX} COMPONENT bin ARCHIVE DESTINATION lib${LIB_SUFFIX} COMPONENT devel - FRAMEWORK DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX} COMPONENT bin) + FRAMEWORK DESTINATION "." COMPONENT bin) + + # add /include as public include directory + target_include_directories(${target} + PUBLIC $ + PRIVATE ${PROJECT_SOURCE_DIR}/src) + + if (SFML_BUILD_FRAMEWORKS) + target_include_directories(${target} INTERFACE $) + else() + target_include_directories(${target} INTERFACE $) + 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() # add a new target which is a SFML example # ex: sfml_add_example(ftp # SOURCES ftp.cpp ... # 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 macro(sfml_add_example target) @@ -187,7 +200,7 @@ macro(sfml_add_example target) # create the target 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}) - target_link_libraries(${target} sfml-main) + target_link_libraries(${target} PRIVATE sfml-main) else() add_executable(${target} ${target_input}) endif() @@ -203,17 +216,17 @@ macro(sfml_add_example target) # link the target to its SFML dependencies if(THIS_DEPENDS) - target_link_libraries(${target} ${THIS_DEPENDS}) + target_link_libraries(${target} PRIVATE ${THIS_DEPENDS}) endif() # add the install rule install(TARGETS ${target} - RUNTIME DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples - BUNDLE DESTINATION ${INSTALL_MISC_DIR}/examples/${target} COMPONENT examples) + RUNTIME DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples + BUNDLE DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples) # install the example's source code install(FILES ${THIS_SOURCES} - DESTINATION ${INSTALL_MISC_DIR}/examples/${target} + DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples) 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}") endif() install(DIRECTORY ${THIS_RESOURCES_DIR} - DESTINATION ${INSTALL_MISC_DIR}/examples/${target} + DESTINATION ${SFML_MISC_INSTALL_PREFIX}/examples/${target} COMPONENT examples) endif() 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 "$") + 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 "$") + endforeach() + endif() +endfunction() + diff --git a/cmake/Modules/FindUDev.cmake b/cmake/Modules/FindUDev.cmake index 9ae3cf807..467bd6931 100644 --- a/cmake/Modules/FindUDev.cmake +++ b/cmake/Modules/FindUDev.cmake @@ -50,3 +50,4 @@ ELSE (UDEV_FOUND) ENDIF (UDev_FIND_REQUIRED) ENDIF (UDEV_FOUND) +mark_as_advanced(UDEV_INCLUDE_DIR UDEV_LIBRARIES) diff --git a/cmake/toolchains/android.toolchain.cmake b/cmake/toolchains/android.toolchain.cmake index 56e70cbaa..ee28e51e4 100644 --- a/cmake/toolchains/android.toolchain.cmake +++ b/cmake/toolchains/android.toolchain.cmake @@ -810,20 +810,16 @@ else() endif() 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} ) - if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) - set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) - endif() + list( SORT ANDROID_SUPPORTED_NATIVE_API_LEVELS ) + set_property( CACHE ANDROID_NATIVE_API_LEVEL PROPERTY STRINGS ${ANDROID_SUPPORTED_NATIVE_API_LEVELS} ) endif() unset( __levelIdx ) # 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 ) -if( CMAKE_VERSION VERSION_GREATER "2.8" ) - list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) - set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) -endif() +list( SORT ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME} ) +set_property( CACHE ANDROID_ABI PROPERTY STRINGS ${ANDROID_SUPPORTED_ABIS_${ANDROID_ARCH_NAME}} ) # runtime choice (STL, rtti, exceptions) @@ -1137,9 +1133,6 @@ if( NOT CMAKE_C_COMPILER ) endif() 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 ) find_program( CMAKE_INSTALL_NAME_TOOL NAMES 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() # 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_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fPIE -pie") else() diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index df02266dc..123b44cf5 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -53,10 +53,10 @@ add_custom_target(doc ALL # setup install rules install(DIRECTORY ${DOXYGEN_OUTPUT_DIR}/html - DESTINATION ${INSTALL_MISC_DIR}/doc + DESTINATION ${SFML_MISC_INSTALL_PREFIX}/doc COMPONENT doc) if(DOXYGEN_HHC_PROGRAM) install(FILES ${DOXYGEN_OUTPUT_DIR}/sfml.chm - DESTINATION ${INSTALL_MISC_DIR}/doc + DESTINATION ${SFML_MISC_INSTALL_PREFIX}/doc COMPONENT doc) endif() diff --git a/examples/X11/CMakeLists.txt b/examples/X11/CMakeLists.txt index cc62f48b6..27509a62e 100644 --- a/examples/X11/CMakeLists.txt +++ b/examples/X11/CMakeLists.txt @@ -4,13 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/X11) # all source files 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 -sfml_add_example(X11 GUI_APP +sfml_add_example(X11Example GUI_APP SOURCES ${SRC} - DEPENDS sfml-window sfml-system ${OPENGL_LIBRARIES} ${X11_LIBRARIES}) + DEPENDS sfml-window OpenGL X11) diff --git a/examples/cocoa/CMakeLists.txt b/examples/cocoa/CMakeLists.txt index 22b9f94a5..ff63cc07c 100644 --- a/examples/cocoa/CMakeLists.txt +++ b/examples/cocoa/CMakeLists.txt @@ -58,4 +58,4 @@ sfml_add_example(cocoa set_target_properties(cocoa PROPERTIES MACOSX_BUNDLE TRUE 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) diff --git a/examples/ftp/CMakeLists.txt b/examples/ftp/CMakeLists.txt index b154e5e06..a65cb67e4 100644 --- a/examples/ftp/CMakeLists.txt +++ b/examples/ftp/CMakeLists.txt @@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/Ftp.cpp) # define the ftp target sfml_add_example(ftp SOURCES ${SRC} - DEPENDS sfml-network sfml-system) + DEPENDS sfml-network) diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt index 14fad5de7..9b8ad49cc 100644 --- a/examples/opengl/CMakeLists.txt +++ b/examples/opengl/CMakeLists.txt @@ -4,13 +4,8 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl) # all source files 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 sfml_add_example(opengl GUI_APP SOURCES ${SRC} - DEPENDS sfml-graphics sfml-window sfml-system ${ADDITIONAL_LIBRARIES} + DEPENDS sfml-graphics OpenGL RESOURCES_DIR resources) diff --git a/examples/pong/CMakeLists.txt b/examples/pong/CMakeLists.txt index 31334fa14..a20f3b192 100644 --- a/examples/pong/CMakeLists.txt +++ b/examples/pong/CMakeLists.txt @@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Pong.cpp) # define the pong target sfml_add_example(pong GUI_APP SOURCES ${SRC} - DEPENDS sfml-audio sfml-graphics sfml-window sfml-system + DEPENDS sfml-audio sfml-graphics RESOURCES_DIR resources) diff --git a/examples/shader/CMakeLists.txt b/examples/shader/CMakeLists.txt index a90b2c951..600cb4d14 100644 --- a/examples/shader/CMakeLists.txt +++ b/examples/shader/CMakeLists.txt @@ -9,5 +9,5 @@ set(SRC # define the shader target sfml_add_example(shader GUI_APP SOURCES ${SRC} - DEPENDS sfml-graphics sfml-window sfml-system + DEPENDS sfml-graphics RESOURCES_DIR resources) diff --git a/examples/sockets/CMakeLists.txt b/examples/sockets/CMakeLists.txt index b9f4b648c..eebc91db5 100644 --- a/examples/sockets/CMakeLists.txt +++ b/examples/sockets/CMakeLists.txt @@ -9,4 +9,4 @@ set(SRC ${SRCROOT}/Sockets.cpp # define the sockets target sfml_add_example(sockets SOURCES ${SRC} - DEPENDS sfml-network sfml-system) + DEPENDS sfml-network) diff --git a/examples/sound/CMakeLists.txt b/examples/sound/CMakeLists.txt index 99c11ca17..d3875a6f7 100644 --- a/examples/sound/CMakeLists.txt +++ b/examples/sound/CMakeLists.txt @@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Sound.cpp) # define the sound target sfml_add_example(sound SOURCES ${SRC} - DEPENDS sfml-audio sfml-system + DEPENDS sfml-audio RESOURCES_DIR resources) diff --git a/examples/sound_capture/CMakeLists.txt b/examples/sound_capture/CMakeLists.txt index e62b3b3bc..e2c457f85 100644 --- a/examples/sound_capture/CMakeLists.txt +++ b/examples/sound_capture/CMakeLists.txt @@ -7,4 +7,4 @@ set(SRC ${SRCROOT}/SoundCapture.cpp) # define the sound-capture target sfml_add_example(sound-capture SOURCES ${SRC} - DEPENDS sfml-audio sfml-system) + DEPENDS sfml-audio) diff --git a/examples/voip/CMakeLists.txt b/examples/voip/CMakeLists.txt index 0e4e710c7..66bc07475 100644 --- a/examples/voip/CMakeLists.txt +++ b/examples/voip/CMakeLists.txt @@ -9,4 +9,4 @@ set(SRC ${SRCROOT}/VoIP.cpp # define the voip target sfml_add_example(voip SOURCES ${SRC} - DEPENDS sfml-audio sfml-network sfml-system) + DEPENDS sfml-audio sfml-network) diff --git a/examples/win32/CMakeLists.txt b/examples/win32/CMakeLists.txt index 1f970600b..bd952c5e6 100644 --- a/examples/win32/CMakeLists.txt +++ b/examples/win32/CMakeLists.txt @@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Win32.cpp) # define the win32 target sfml_add_example(win32 GUI_APP SOURCES ${SRC} - DEPENDS sfml-graphics sfml-window sfml-system + DEPENDS sfml-graphics RESOURCES_DIR resources) diff --git a/examples/window/CMakeLists.txt b/examples/window/CMakeLists.txt index 2ce61a077..b106c0435 100644 --- a/examples/window/CMakeLists.txt +++ b/examples/window/CMakeLists.txt @@ -4,12 +4,7 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/window) # all source files 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 sfml_add_example(window GUI_APP SOURCES ${SRC} - DEPENDS sfml-window sfml-system ${ADDITIONAL_LIBRARIES}) + DEPENDS sfml-window OpenGL) diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index 65c0fc8fe..420e13b55 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -66,35 +66,25 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -if(SFML_OS_IOS) - find_host_package(OpenAL REQUIRED) - find_host_package(Vorbis REQUIRED) - find_host_package(FLAC REQUIRED) -else() - find_package(OpenAL REQUIRED) - find_package(Vorbis REQUIRED) - find_package(FLAC REQUIRED) -endif() +sfml_find_package(OpenAL INCLUDE "OPENAL_INCLUDE_DIR" LINK "OPENAL_LIBRARY") +sfml_find_package(Vorbis INCLUDE "VORBIS_INCLUDE_DIRS" LINK "VORBIS_LIBRARIES") +sfml_find_package(FLAC INCLUDE "FLAC_INCLUDE_DIR" LINK "FLAC_LIBRARY") -include_directories(${OPENAL_INCLUDE_DIR}) -include_directories(${VORBIS_INCLUDE_DIRS}) -include_directories(${FLAC_INCLUDE_DIR}) -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}) +# avoids warnings in vorbisfile.h +target_compile_definitions(Vorbis INTERFACE "OV_EXCLUDE_STATIC_CALLBACKS") +target_compile_definitions(FLAC INTERFACE "FLAC__NO_DLL") # define the sfml-audio target sfml_add_library(sfml-audio - SOURCES ${SRC} ${CODECS_SRC} - DEPENDS sfml-system - EXTERNAL_LIBS ${AUDIO_EXT_LIBS}) + SOURCES ${SRC} ${CODECS_SRC}) + +# 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) diff --git a/src/SFML/CMakeLists.txt b/src/SFML/CMakeLists.txt index 30f674afd..25a5bb1c7 100644 --- a/src/SFML/CMakeLists.txt +++ b/src/SFML/CMakeLists.txt @@ -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}") endif() -# add the SFML sources path -include_directories(${PROJECT_SOURCE_DIR}/src) - # define the path of our additional CMake modules set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 42d34c9c2..883c75815 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -88,8 +88,16 @@ set(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 -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 if(SFML_OS_WINDOWS) @@ -104,53 +112,36 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -if(NOT SFML_OPENGL_ES) - find_package(OpenGL REQUIRED) +if(SFML_OPENGL_ES) 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() - 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() - find_package(Freetype REQUIRED) -endif() -include_directories(${FREETYPE_INCLUDE_DIRS}) + # Target OpenGL already defined for Window component so no sfml_find_package() here + target_link_libraries(sfml-graphics PRIVATE OpenGL) -# 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) - 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() -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() -if(SFML_OS_IOS) - list(APPEND GRAPHICS_EXT_LIBS "-framework OpenGLES") -elseif(SFML_OS_ANDROID) - list(APPEND GRAPHICS_EXT_LIBS z) -endif() -list(APPEND GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY}) + +sfml_find_package(Freetype INCLUDE "FREETYPE_INCLUDE_DIRS" LINK "FREETYPE_LIBRARY") +target_link_libraries(sfml-graphics PRIVATE Freetype) # 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 # when gcc is used; otherwise saving PNGs may crash in stb_image_write if(SFML_COMPILER_GCC) set_source_files_properties(${SRCROOT}/ImageLoader.cpp PROPERTIES COMPILE_FLAGS -fno-strict-aliasing) 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}) diff --git a/src/SFML/Main/CMakeLists.txt b/src/SFML/Main/CMakeLists.txt index d18ee4095..6542e591d 100644 --- a/src/SFML/Main/CMakeLists.txt +++ b/src/SFML/Main/CMakeLists.txt @@ -12,26 +12,20 @@ elseif(SFML_OS_ANDROID) else() return() endif() -source_group("" FILES ${SRC}) # define the sfml-main target -add_library(sfml-main STATIC ${SRC}) +sfml_add_library(sfml-main STATIC SOURCES ${SRC}) -# set the debug suffix -set_target_properties(sfml-main PROPERTIES DEBUG_POSTFIX -d) - -# insert the major version number in the output filename -set_target_properties(sfml-main PROPERTIES OUTPUT_NAME "sfml-main") - -# 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) +# overwrite sfml-main suffix for backward compatibility with FindSFML.cmake +set_target_properties(sfml-main PROPERTIES + DEBUG_POSTFIX -d + RELEASE_POSTFIX "" + MINSIZEREL_POSTFIX "" + RELWITHDEBINFO_POSTFIX "") # because of a current limitation on Android (which prevents one library # from depending on shared libraries), we need a boostrap activity which # will load our shared libraries manually 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() diff --git a/src/SFML/Network/CMakeLists.txt b/src/SFML/Network/CMakeLists.txt index d1ff75724..6626d7349 100644 --- a/src/SFML/Network/CMakeLists.txt +++ b/src/SFML/Network/CMakeLists.txt @@ -44,14 +44,12 @@ endif() 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 sfml_add_library(sfml-network - SOURCES ${SRC} - DEPENDS sfml-system - EXTERNAL_LIBS ${NETWORK_EXT_LIBS}) + SOURCES ${SRC}) + +# setup dependencies +target_link_libraries(sfml-network PUBLIC sfml-system) +if(SFML_OS_WINDOWS) + target_link_libraries(sfml-network PRIVATE ws2_32) +endif() diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 54da9a07c..d1b712d86 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -85,21 +85,18 @@ else() source_group("unix" FILES ${PLATFORM_SRC}) 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 sfml_add_library(sfml-system - SOURCES ${SRC} ${PLATFORM_SRC} - EXTERNAL_LIBS ${SYSTEM_EXT_LIBS}) + SOURCES ${SRC} ${PLATFORM_SRC}) + +# 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() diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 570d6b131..55083dbdf 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -218,70 +218,53 @@ elseif(SFML_OS_ANDROID) source_group("android" FILES ${PLATFORM_SRC}) 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) - find_package(X11 REQUIRED) - if(NOT X11_FOUND) - message(FATAL_ERROR "X11 library not found") + sfml_find_package(X11 INCLUDE "X11_INCLUDE_DIR" LINK "X11_X11_LIB" "X11_Xrandr_LIB") + target_link_libraries(sfml-window PRIVATE X11) +endif() + +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() - if(NOT X11_Xrandr_FOUND) - message(FATAL_ERROR "Xrandr library not found") - endif() - include_directories(${X11_INCLUDE_DIR}) -endif() -if(NOT SFML_OPENGL_ES) - 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}) +else() + sfml_find_package(OpenGL INCLUDE "OPENGL_INCLUDE_DIR" LINK "OPENGL_gl_LIBRARY") + target_link_libraries(sfml-window PRIVATE OpenGL) endif() + if(SFML_OS_WINDOWS AND NOT SFML_COMPILER_MSVC) include(CheckIncludeFile) check_include_file(dinput.h 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() +if(SFML_OPENGL_ES AND SFML_OS_LINUX) + 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-window PRIVATE EGL GLES) +endif() -# build the list of external libraries to link -if(SFML_OS_WINDOWS) - list(APPEND WINDOW_EXT_LIBS winmm gdi32) -elseif(SFML_OS_LINUX) - list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES}) +if(SFML_OS_LINUX) + 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) - list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} usbhid) + target_link_libraries(sfml-window PRIVATE usbhid) elseif(SFML_OS_MACOSX) - list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon") + target_link_libraries(sfml-window PRIVATE "-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") + target_link_libraries(sfml-window PRIVATE "-framework Foundation" "-framework UIKit" "-framework CoreGraphics" "-framework QuartzCore" "-framework CoreMotion") elseif(SFML_OS_ANDROID) - list(APPEND WINDOW_EXT_LIBS android) + target_link_libraries(sfml-window PRIVATE android) endif() -if(SFML_OPENGL_ES) - if(SFML_OS_LINUX) - list(APPEND WINDOW_EXT_LIBS ${EGL_LIBRARY} ${GLES_LIBRARY}) - elseif(SFML_OS_IOS) - list(APPEND WINDOW_EXT_LIBS "-framework OpenGLES") - elseif(SFML_OS_ANDROID) - list(APPEND WINDOW_EXT_LIBS EGL GLESv1_CM) - 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}) diff --git a/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in b/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in index 624afefe8..3a7cfd0eb 100644 --- a/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in +++ b/tools/xcode/templates/SFML/SFML App.xctemplate/TemplateInfo.plist.in @@ -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. # 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" 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 for f in "FLAC" "ogg" "vorbis" "vorbisenc" "vorbisfile" "OpenAL" do - copy "$CMAKE_INSTALL_FRAMEWORK_PREFIX/$f.framework" "$dest/$f.framework" + copy "$SFML_DEPENDENCIES_INSTALL_PREFIX/$f.framework" "$dest/$f.framework" done elif [ "$1" = "graphics" ] then - copy "$CMAKE_INSTALL_FRAMEWORK_PREFIX/freetype.framework" "$dest/freetype.framework" + copy "$SFML_DEPENDENCIES_INSTALL_PREFIX/freetype.framework" "$dest/freetype.framework" fi fi }