Modernize CMake files
This commit is contained in:
parent
fc02cf004a
commit
ee08e18726
26 changed files with 259 additions and 275 deletions
|
@ -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)
|
||||
|
|
|
@ -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/")
|
||||
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue