Uniformized the way CMake find and link against external libraries

This commit is contained in:
Jonathan De Wachter 2013-12-19 00:59:09 +01:00
parent d40399e431
commit 565bc69a4e
5 changed files with 61 additions and 63 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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

View File

@ -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

View File

@ -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