Added CMake variables to select the modules to be built

This addresses issue #798.
This commit is contained in:
Mario Liebisch 2015-02-21 14:46:46 +01:00 committed by Lukas Dürrenberger
parent 973ac8ddcd
commit 0b2ac85f11
3 changed files with 160 additions and 46 deletions

View File

@ -73,11 +73,21 @@ else()
set(SFML_BUILD_EXAMPLES FALSE) set(SFML_BUILD_EXAMPLES FALSE)
endif() endif()
# add options to select which modules to build
sfml_set_option(SFML_BUILD_WINDOW TRUE BOOL "TRUE to build SFML's Window module. This setting is ignored, if the graphics module is built.")
sfml_set_option(SFML_BUILD_GRAPHICS TRUE BOOL "TRUE to build SFML's Graphics module.")
if(NOT SFML_OS_IOS)
sfml_set_option(SFML_BUILD_AUDIO TRUE BOOL "TRUE to build SFML's Audio module.")
endif()
sfml_set_option(SFML_BUILD_NETWORK TRUE BOOL "TRUE to build SFML's Network module.")
# add an option for building the API documentation # add an option for building the API documentation
sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it") sfml_set_option(SFML_BUILD_DOC FALSE BOOL "TRUE to generate the API documentation, FALSE to ignore it")
# add an option for choosing the OpenGL implementation # add an option for choosing the OpenGL implementation
if(SFML_BUILD_WINDOW)
sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation") sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation")
endif()
# Mac OS X specific options # Mac OS X specific options
if(SFML_OS_MACOSX) if(SFML_OS_MACOSX)
@ -135,6 +145,12 @@ if(NOT BUILD_SHARED_LIBS)
add_definitions(-DSFML_STATIC) add_definitions(-DSFML_STATIC)
endif() endif()
# force building sfml-window, if sfml-graphics module is built
if(SFML_BUILD_GRAPHICS AND NOT SFML_BUILD_WINDOW)
message(WARNING "You're trying to build SFML's Graphics module without the Window module. Forcing building of the Window module as a dependency.")
set(SFML_BUILD_WINDOW TRUE)
endif()
# allow not using bundled dependencies with a switch # allow not using bundled dependencies with a switch
# (except for stb_image) # (except for stb_image)
# yes this is horrible, but GLOB_RECURSE sucks # yes this is horrible, but GLOB_RECURSE sucks
@ -231,7 +247,7 @@ if(SFML_OS_MACOSX)
endif() endif()
# only the default architecture (i.e. 64-bit) is supported # only the default architecture (i.e. 64-bit) is supported
if(CMAKE_OSX_ARCHITECTURES AND NOT "${CMAKE_OSX_ARCHITECTURES}" STREQUAL "x86_64") if(CMAKE_OSX_ARCHITECTURES AND NOT CMAKE_OSX_ARCHITECTURES STREQUAL "x86_64")
message(FATAL_ERROR "Only 64-bit architecture is supported") message(FATAL_ERROR "Only 64-bit architecture is supported")
return() return()
endif() endif()
@ -240,6 +256,30 @@ if(SFML_OS_MACOSX)
set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)") set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)")
endif() endif()
if(SFML_OS_LINUX OR SFML_OS_FREEBSD)
set(PKGCONFIG_DIR lib${LIB_SUFFIX}/pkgconfig)
if(SFML_OS_FREEBSD)
set(PKGCONFIG_DIR libdata/pkgconfig)
endif()
if(BUILD_SHARED_LIBS)
sfml_set_option(SFML_INSTALL_PKGCONFIG_FILES FALSE BOOL "TRUE to automatically install pkg-config files so other projects can find SFML")
if(SFML_INSTALL_PKGCONFIG_FILES)
foreach(sfml_module IN ITEMS all system window graphics audio network)
CONFIGURE_FILE(
"tools/pkg-config/sfml-${sfml_module}.pc.in"
"tools/pkg-config/sfml-${sfml_module}.pc"
@ONLY)
INSTALL(FILES "${CMAKE_CURRENT_BINARY_DIR}/tools/pkg-config/sfml-${sfml_module}.pc"
DESTINATION "${CMAKE_INSTALL_PREFIX}/${PKGCONFIG_DIR}")
endforeach()
endif()
else()
if(SFML_INSTALL_PKGCONFIG_FILES)
message(WARNING "No pkg-config files are provided for the static SFML libraries (SFML_INSTALL_PKGCONFIG_FILES will be ignored).")
endif()
endif()
endif()
# enable project folders # enable project folders
set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake")
@ -306,10 +346,46 @@ else()
MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}
PUBLIC_HEADER "${SFML_HEADERS}") PUBLIC_HEADER "${SFML_HEADERS}")
# add the remaining headers # add the non-optional SFML headers
add_custom_command(TARGET SFML add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
POST_BUILD ${PROJECT_SOURCE_DIR}/include/SFML/Config.hpp
COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* $<TARGET_FILE_DIR:SFML>/Headers) ${PROJECT_SOURCE_DIR}/include/SFML/OpenGL.hpp
${PROJECT_SOURCE_DIR}/include/SFML/System.hpp
${PROJECT_SOURCE_DIR}/include/SFML/Main.hpp
${PROJECT_SOURCE_DIR}/include/SFML/System
$<TARGET_FILE_DIR:SFML>/Headers)
# add window module headers if enabled
if(SFML_BUILD_WINDOW)
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
${PROJECT_SOURCE_DIR}/include/SFML/Window.hpp
${PROJECT_SOURCE_DIR}/include/SFML/Window
$<TARGET_FILE_DIR:SFML>/Headers)
endif()
# add network module headers if enabled
if(SFML_BUILD_GRAPHICS)
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
${PROJECT_SOURCE_DIR}/include/SFML/Network.hpp
${PROJECT_SOURCE_DIR}/include/SFML/Network
$<TARGET_FILE_DIR:SFML>/Headers)
endif()
# add graphics module headers if enabled
if(SFML_BUILD_GRAPHICS)
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
${PROJECT_SOURCE_DIR}/include/SFML/Graphics.hpp
${PROJECT_SOURCE_DIR}/include/SFML/Graphics
$<TARGET_FILE_DIR:SFML>/Headers)
endif()
# add audio module headers if enabled
if(SFML_BUILD_AUDIO)
add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r
${PROJECT_SOURCE_DIR}/include/SFML/Audio.hpp
${PROJECT_SOURCE_DIR}/include/SFML/Audio
$<TARGET_FILE_DIR:SFML>/Headers)
endif()
# adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle # adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle
# NOTE: it's not required to link against SFML.framework # NOTE: it's not required to link against SFML.framework
@ -356,33 +432,37 @@ if(SFML_OS_WINDOWS)
elseif(SFML_OS_MACOSX) elseif(SFML_OS_MACOSX)
# install extlibs dependencies only when used # install extlibs dependencies only when used
if("${FLAC_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework") 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})
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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
if("${FREETYPE_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/freetype.framework") if(OGG_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework")
install(DIRECTORY extlibs/libs-osx/Frameworks/freetype.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
if("${VORBIS_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbis.framework") 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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
if("${VORBISENC_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisenc.framework") 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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
if("${VORBISFILE_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/vorbisfile.framework") 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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
if("${OPENAL_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework") 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 ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
endif() endif()
endif()
# install the Xcode templates if requested # install the Xcode templates if requested
if(SFML_INSTALL_XCODE_TEMPLATES) if(SFML_INSTALL_XCODE_TEMPLATES)
@ -408,7 +488,9 @@ elseif(SFML_OS_IOS)
# since the iOS libraries are built as static, we must install the SFML dependencies # since the iOS libraries are built as static, we must install the SFML dependencies
# too so that the end user can easily link them to its final application # too so that the end user can easily link them to its final application
if(SFML_BUILD_GRAPHICS)
install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib) install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib)
endif()
elseif(SFML_OS_ANDROID) elseif(SFML_OS_ANDROID)

View File

@ -1,14 +1,22 @@
# add the examples subdirectories # add the examples subdirectories
if(SFML_BUILD_NETWORK)
add_subdirectory(ftp) add_subdirectory(ftp)
add_subdirectory(opengl)
add_subdirectory(pong)
add_subdirectory(shader)
add_subdirectory(sockets) add_subdirectory(sockets)
endif()
if(SFML_BUILD_NETWORK AND SFML_BUILD_AUDIO)
add_subdirectory(voip)
endif()
if(SFML_BUILD_AUDIO)
add_subdirectory(sound) add_subdirectory(sound)
add_subdirectory(sound_capture) add_subdirectory(sound_capture)
add_subdirectory(voip) endif()
if(SFML_BUILD_WINDOW)
add_subdirectory(window) add_subdirectory(window)
endif()
if(SFML_BUILD_GRAPHICS)
add_subdirectory(opengl)
add_subdirectory(shader)
if(SFML_OS_WINDOWS) if(SFML_OS_WINDOWS)
add_subdirectory(win32) add_subdirectory(win32)
elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
@ -16,3 +24,7 @@ elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD)
elseif(SFML_OS_MACOSX) elseif(SFML_OS_MACOSX)
add_subdirectory(cocoa) add_subdirectory(cocoa)
endif() endif()
endif()
if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO)
add_subdirectory(pong)
endif()

View File

@ -49,11 +49,31 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/")
set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib")
# add the modules subdirectories # add the modules subdirectories
# sfml-system
add_subdirectory(System) add_subdirectory(System)
# sfml-main and sfml-activity
if(SFML_OS_WINDOWS OR SFML_OS_ANDROID OR SFML_OS_IOS) if(SFML_OS_WINDOWS OR SFML_OS_ANDROID OR SFML_OS_IOS)
add_subdirectory(Main) add_subdirectory(Main)
endif() endif()
# sfml-window
if(SFML_BUILD_WINDOW OR SFML_BUILD_GRAPHICS)
add_subdirectory(Window) add_subdirectory(Window)
endif()
# sfml-network
if(SFML_BUILD_NETWORK)
add_subdirectory(Network) add_subdirectory(Network)
endif()
# sfml-graphics
if(SFML_BUILD_GRAPHICS)
add_subdirectory(Graphics) add_subdirectory(Graphics)
endif()
# sfml-audio
if(SFML_BUILD_AUDIO)
add_subdirectory(Audio) add_subdirectory(Audio)
endif()