From 565bc69a4e6e0b5ee6df203e76172e9736d72517 Mon Sep 17 00:00:00 2001 From: Jonathan De Wachter Date: Thu, 19 Dec 2013 00:59:09 +0100 Subject: [PATCH] Uniformized the way CMake find and link against external libraries --- CMakeLists.txt | 1 + src/SFML/Audio/CMakeLists.txt | 18 ++++-------- src/SFML/Graphics/CMakeLists.txt | 48 ++++++++++++++++---------------- src/SFML/System/CMakeLists.txt | 13 ++++----- src/SFML/Window/CMakeLists.txt | 44 ++++++++++++++++------------- 5 files changed, 61 insertions(+), 63 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ad6a4bd76..54d9cf9a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -104,6 +104,7 @@ endif() # define SFML_OPENGL_ES if needed if(SFML_OPENGL_ES) add_definitions(-DSFML_OPENGL_ES) + add_definitions(-DGL_GLEXT_PROTOTYPES) endif() # define an option for choosing between static and dynamic C runtime (Windows only) diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index cf3b38e5e..078d7e17f 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -46,26 +46,20 @@ endif() if(NOT SFML_OS_ANDROID) find_package(OpenAL REQUIRED) find_package(Sndfile REQUIRED) - set(AUDIO_EXT_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY}) else() find_host_package(OpenAL REQUIRED) find_host_package(Sndfile REQUIRED) - set(AUDIO_EXT_INCLUDE_PATHS ${OPENAL_INCLUDE_DIRS} ${SNDFILE_INCLUDE_DIR}) - set(AUDIO_EXT_LIBS -landroid -lOpenSLES ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY}) endif() - -# add include paths of external libraries include_directories(${OPENAL_INCLUDE_DIR} ${SNDFILE_INCLUDE_DIR}) +# build the list of external libraries to link +if(SFML_OS_ANDROID) + list(APPEND AUDIO_EXT_LIBS -landroid -lOpenSLES) +endif() +list(APPEND AUDIO_EXT_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY}) + # define the sfml-audio target -if(NOT SFML_OS_ANDROID) -sfml_add_library(sfml-audio - SOURCES ${SRC} - DEPENDS sfml-system - EXTERNAL_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY}) -else() sfml_add_library(sfml-audio SOURCES ${SRC} DEPENDS sfml-system EXTERNAL_LIBS ${AUDIO_EXT_LIBS}) -endif() diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index dbbd6eadf..59ae577db 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -109,42 +109,42 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -if(NOT OPENGL_ES) +if(NOT SFML_OPENGL_ES) find_package(OpenGL REQUIRED) - find_package(Freetype REQUIRED) find_package(GLEW REQUIRED) - find_package(JPEG REQUIRED) if(SFML_OS_LINUX) find_package(X11 REQUIRED) endif() - set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) - set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY}) - - # build the list of libraries to link - set(GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY} ${OPENGL_gl_LIBRARY}) - if(SFML_OS_LINUX) - set(GRAPHICS_EXT_LIBS ${GRAPHICS_EXT_LIBS} ${X11_LIBRARIES}) - endif() + include_directories(${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) endif() - -if(SFML_OS_IOS) - find_package(JPEG REQUIRED) - find_package(Freetype REQUIRED) - set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR}) - set(GRAPHICS_EXT_LIBS "-framework OpenGLES ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}") -elseif(SFML_OS_ANDROID) +if(SFML_OS_ANDROID) find_host_package(JPEG REQUIRED) find_host_package(Freetype REQUIRED) - set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR}) - set(GRAPHICS_EXT_LIBS -lz ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) - add_definitions(-DGL_GLEXT_PROTOTYPES) +else() + find_package(JPEG REQUIRED) + find_package(Freetype REQUIRED) endif() +include_directories(${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR}) -# add include paths of external libraries -include_directories(${GRAPHICS_EXT_INCLUDE_PATHS}) +# build the list of external libraries to link +if(NOT SFML_OPENGL_ES) + list(APPEND GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${GLEW_LIBRARY} ${JPEG_LIBRARY} ${OPENGL_gl_LIBRARY}) + if(SFML_OS_LINUX) + list(APPEND GRAPHICS_EXT_LIBS ${X11_LIBRARIES}) + endif() +endif() +if(SFML_OS_IOS) + list(APPEND GRAPHICS_EXT_LIBS "-framework OpenGLES") +elseif(SFML_OS_ANDROID) + list(APPEND GRAPHICS_EXT_LIBS -lz) +endif() +list(APPEND GRAPHICS_EXT_LIBS ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) # add preprocessor symbols -add_definitions(-DGLEW_STATIC -DSTBI_FAILURE_USERMSG) +if(NOT SFML_OPENGL_ES) + add_definitions(-DGLEW_STATIC) +endif() +add_definitions(-DSTBI_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 diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 2eacc0dce..080320a3b 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -79,21 +79,18 @@ else() source_group("unix" FILES ${PLATFORM_SRC}) endif() -# build the list of external libraries to link -set(SYSTEM_EXT_LIBS) +# build the list of external libraries to link if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX) - set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} pthread) + list(APPEND SYSTEM_EXT_LIBS pthread) endif() if(SFML_OS_LINUX) - set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} rt) + list(APPEND SYSTEM_EXT_LIBS rt) endif() if(SFML_OS_WINDOWS) - set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} winmm) + list(APPEND SYSTEM_EXT_LIBS winmm) endif() - -# pthread is implicitly linked by the NDK if(SFML_OS_ANDROID) - set(SYSTEM_EXT_LIBS android) + list(APPEND SYSTEM_EXT_LIBS android) endif() # define the sfml-system target diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index dba677601..9732ac069 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -146,7 +146,6 @@ elseif(SFML_OS_ANDROID) ${SRCROOT}/Android/WindowImplAndroid.cpp ${SRCROOT}/Android/EglContext.hpp ${SRCROOT}/Android/EglContext.cpp - #${SRCROOT}/Android/VideoModeImpl.hpp ${SRCROOT}/Android/VideoModeImpl.cpp ${SRCROOT}/Android/InputImpl.hpp ${SRCROOT}/Android/InputImpl.cpp @@ -156,39 +155,46 @@ elseif(SFML_OS_ANDROID) endif() # find external libraries -if(NOT OPENGL_ES) +if(NOT SFML_OPENGL_ES) find_package(OpenGL REQUIRED) include_directories(${OPENGL_INCLUDE_DIR}) - if(SFML_OS_LINUX AND NOT SFML_OS_ANDROID) + if(SFML_OS_LINUX OR SFML_OS_FREEBSD) find_package(X11 REQUIRED) if(NOT X11_Xrandr_FOUND) message(FATAL_ERROR "Xrandr library not found") endif() - include_directories(${X11_INCLUDE_DIR}) + include_directories(${X11_INCLUDE_DIR}) + find_package(UDev REQUIRED) + if(NOT UDEV_FOUND) + message(FATAL_ERROR "udev library not found") + endif() + include_directories(${UDEV_INCLUDE_DIR}) endif() - include_directories(${X11_INCLUDE_DIR}) - - find_package(UDev REQUIRED) - if(NOT UDEV_FOUND) - message(FATAL_ERROR "udev library not found") - endif() - include_directories(${UDEV_INCLUDE_DIR}) endif() # build the list of external libraries to link -if(SFML_OS_WINDOWS) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} winmm gdi32) -elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES}) +if(SFML_OS_WINDOWS) + list(APPEND WINDOW_EXT_LIBS winmm gdi32) +elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) + list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES}) if(SFML_OS_FREEBSD) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} usbhid) + list(APPEND WINDOW_EXT_LIBS usbhid) endif() elseif(SFML_OS_MACOSX) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} "-framework Foundation -framework AppKit -framework IOKit -framework Carbon") + list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework AppKit -framework IOKit -framework Carbon") elseif(SFML_OS_IOS) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} "-framework OpenGLES -framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework CoreMotion") + list(APPEND WINDOW_EXT_LIBS "-framework Foundation -framework UIKit -framework CoreGraphics -framework QuartzCore -framework CoreMotion") elseif(SFML_OS_ANDROID) - set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} "-landroid -llog -lEGL -lGLESv1_CM") + list(APPEND WINDOW_EXT_LIBS "-landroid") +endif() +if(SFML_OPENGL_ES) + if(SFML_OS_IOS) + list(APPEND WINDOW_EXT_LIBS "-framework OpenGLES") + elseif(SFML_OS_ANDROID) + list(APPEND WINDOW_EXT_LIBS "-lEGL -lGLESv1_CM") + endif() +else() + list(APPEND WINDOW_EXT_LIBS ${OPENGL_gl_LIBRARY}) endif() # define the sfml-window target