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 # define SFML_OPENGL_ES if needed
if(SFML_OPENGL_ES) if(SFML_OPENGL_ES)
add_definitions(-DSFML_OPENGL_ES) add_definitions(-DSFML_OPENGL_ES)
add_definitions(-DGL_GLEXT_PROTOTYPES)
endif() endif()
# define an option for choosing between static and dynamic C runtime (Windows only) # 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) if(NOT SFML_OS_ANDROID)
find_package(OpenAL REQUIRED) find_package(OpenAL REQUIRED)
find_package(Sndfile REQUIRED) find_package(Sndfile REQUIRED)
set(AUDIO_EXT_LIBS ${OPENAL_LIBRARY} ${SNDFILE_LIBRARY})
else() else()
find_host_package(OpenAL REQUIRED) find_host_package(OpenAL REQUIRED)
find_host_package(Sndfile 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() endif()
# add include paths of external libraries
include_directories(${OPENAL_INCLUDE_DIR} ${SNDFILE_INCLUDE_DIR}) 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 # 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 sfml_add_library(sfml-audio
SOURCES ${SRC} SOURCES ${SRC}
DEPENDS sfml-system DEPENDS sfml-system
EXTERNAL_LIBS ${AUDIO_EXT_LIBS}) EXTERNAL_LIBS ${AUDIO_EXT_LIBS})
endif()

View File

@ -109,42 +109,42 @@ elseif(SFML_OS_ANDROID)
endif() endif()
# find external libraries # find external libraries
if(NOT OPENGL_ES) if(NOT SFML_OPENGL_ES)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
find_package(Freetype REQUIRED)
find_package(GLEW REQUIRED) find_package(GLEW REQUIRED)
find_package(JPEG REQUIRED)
if(SFML_OS_LINUX) if(SFML_OS_LINUX)
find_package(X11 REQUIRED) find_package(X11 REQUIRED)
endif() endif()
set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${GLEW_INCLUDE_PATH} ${JPEG_INCLUDE_DIR} ${OPENGL_INCLUDE_DIR}) include_directories(${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()
endif() endif()
if(SFML_OS_ANDROID)
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)
find_host_package(JPEG REQUIRED) find_host_package(JPEG REQUIRED)
find_host_package(Freetype REQUIRED) find_host_package(Freetype REQUIRED)
set(GRAPHICS_EXT_INCLUDE_PATHS ${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR}) else()
set(GRAPHICS_EXT_LIBS -lz ${FREETYPE_LIBRARY} ${JPEG_LIBRARY}) find_package(JPEG REQUIRED)
add_definitions(-DGL_GLEXT_PROTOTYPES) find_package(Freetype REQUIRED)
endif() endif()
include_directories(${FREETYPE_INCLUDE_DIRS} ${JPEG_INCLUDE_DIR})
# add include paths of external libraries # build the list of external libraries to link
include_directories(${GRAPHICS_EXT_INCLUDE_PATHS}) 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 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 # 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

View File

@ -79,21 +79,18 @@ else()
source_group("unix" FILES ${PLATFORM_SRC}) source_group("unix" FILES ${PLATFORM_SRC})
endif() endif()
# build the list of external libraries to link # build the list of external libraries to link
set(SYSTEM_EXT_LIBS)
if(SFML_OS_LINUX OR SFML_OS_FREEBSD OR SFML_OS_MACOSX) 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() endif()
if(SFML_OS_LINUX) if(SFML_OS_LINUX)
set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} rt) list(APPEND SYSTEM_EXT_LIBS rt)
endif() endif()
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
set(SYSTEM_EXT_LIBS ${SYSTEM_EXT_LIBS} winmm) list(APPEND SYSTEM_EXT_LIBS winmm)
endif() endif()
# pthread is implicitly linked by the NDK
if(SFML_OS_ANDROID) if(SFML_OS_ANDROID)
set(SYSTEM_EXT_LIBS android) list(APPEND SYSTEM_EXT_LIBS android)
endif() endif()
# define the sfml-system target # define the sfml-system target

View File

@ -146,7 +146,6 @@ elseif(SFML_OS_ANDROID)
${SRCROOT}/Android/WindowImplAndroid.cpp ${SRCROOT}/Android/WindowImplAndroid.cpp
${SRCROOT}/Android/EglContext.hpp ${SRCROOT}/Android/EglContext.hpp
${SRCROOT}/Android/EglContext.cpp ${SRCROOT}/Android/EglContext.cpp
#${SRCROOT}/Android/VideoModeImpl.hpp
${SRCROOT}/Android/VideoModeImpl.cpp ${SRCROOT}/Android/VideoModeImpl.cpp
${SRCROOT}/Android/InputImpl.hpp ${SRCROOT}/Android/InputImpl.hpp
${SRCROOT}/Android/InputImpl.cpp ${SRCROOT}/Android/InputImpl.cpp
@ -156,39 +155,46 @@ elseif(SFML_OS_ANDROID)
endif() endif()
# find external libraries # find external libraries
if(NOT OPENGL_ES) if(NOT SFML_OPENGL_ES)
find_package(OpenGL REQUIRED) find_package(OpenGL REQUIRED)
include_directories(${OPENGL_INCLUDE_DIR}) 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) find_package(X11 REQUIRED)
if(NOT X11_Xrandr_FOUND) if(NOT X11_Xrandr_FOUND)
message(FATAL_ERROR "Xrandr library not found") message(FATAL_ERROR "Xrandr library not found")
endif() 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() 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() endif()
# build the list of external libraries to link # build the list of external libraries to link
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} ${OPENGL_gl_LIBRARY} winmm gdi32) list(APPEND WINDOW_EXT_LIBS winmm gdi32)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) 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}) list(APPEND WINDOW_EXT_LIBS ${X11_X11_LIB} ${X11_Xrandr_LIB} ${UDEV_LIBRARIES})
if(SFML_OS_FREEBSD) if(SFML_OS_FREEBSD)
set(WINDOW_EXT_LIBS ${WINDOW_EXT_LIBS} usbhid) list(APPEND WINDOW_EXT_LIBS usbhid)
endif() endif()
elseif(SFML_OS_MACOSX) 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) 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) 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() endif()
# define the sfml-window target # define the sfml-window target