From 40cb8cd54e204f6feb43086171ea813fbf5085f8 Mon Sep 17 00:00:00 2001 From: Mario Liebisch Date: Sat, 21 Feb 2015 14:46:46 +0100 Subject: [PATCH] Added CMake variables to select the modules to be built This addresses issue #798. --- CMakeLists.txt | 38 +++++++++++++++++++++++++------------ examples/CMakeLists.txt | 42 ++++++++++++++++++++++++++--------------- src/SFML/CMakeLists.txt | 28 +++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 77589da764..72af5b0fee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,11 +68,21 @@ else() set(SFML_BUILD_EXAMPLES FALSE) 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 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 -sfml_set_option(SFML_OPENGL_ES ${OPENGL_ES} BOOL "TRUE to use an OpenGL ES implementation, FALSE to use a desktop OpenGL implementation") +if(SFML_BUILD_GRAPHICS OR 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") +endif() # Mac OS X specific options if(SFML_OS_MACOSX) @@ -193,11 +203,11 @@ if(SFML_OS_MACOSX) endif() # 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") return() endif() - + # configure Xcode templates set(XCODE_TEMPLATES_ARCH "\$(NATIVE_ARCH_ACTUAL)") endif() @@ -329,31 +339,33 @@ if(SFML_OS_WINDOWS) elseif(SFML_OS_MACOSX) # install extlibs dependencies only when used - if("${FLAC_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/FLAC.framework") + if(SFML_BUILD_AUDIO AND 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}) endif() - 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}) + 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("${OGG_LIBRARY}" STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/ogg.framework") + 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}) 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}) 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}) 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}) 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}) endif() @@ -381,7 +393,9 @@ elseif(SFML_OS_IOS) # 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 - install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib) + if(SFML_BUILD_GRAPHICS) + install(FILES extlibs/libs-ios/libfreetype.a extlibs/libs-ios/libjpeg.a DESTINATION lib) + endif() elseif(SFML_OS_ANDROID) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index a55137d64d..872c77d9cd 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,18 +1,30 @@ # add the examples subdirectories -add_subdirectory(ftp) -add_subdirectory(opengl) -add_subdirectory(pong) -add_subdirectory(shader) -add_subdirectory(sockets) -add_subdirectory(sound) -add_subdirectory(sound_capture) -add_subdirectory(voip) -add_subdirectory(window) -if(SFML_OS_WINDOWS) - add_subdirectory(win32) -elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) - add_subdirectory(X11) -elseif(SFML_OS_MACOSX) - add_subdirectory(cocoa) +if(SFML_BUILD_NETWORK) + add_subdirectory(ftp) + 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_capture) +endif() +if(SFML_BUILD_WINDOW) + add_subdirectory(window) +endif() +if(SFML_BUILD_GRAPHICS) + add_subdirectory(opengl) + add_subdirectory(shader) + if(SFML_OS_WINDOWS) + add_subdirectory(win32) + elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) + add_subdirectory(X11) + elseif(SFML_OS_MACOSX) + add_subdirectory(cocoa) + endif() +endif() +if(SFML_BUILD_GRAPHICS AND SFML_BUILD_AUDIO) + add_subdirectory(pong) endif() diff --git a/src/SFML/CMakeLists.txt b/src/SFML/CMakeLists.txt index 8eb334d95f..61be9ae6a0 100644 --- a/src/SFML/CMakeLists.txt +++ b/src/SFML/CMakeLists.txt @@ -49,11 +49,31 @@ set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/Modules/") set(LIBRARY_OUTPUT_PATH "${PROJECT_BINARY_DIR}/lib") # add the modules subdirectories + +# sfml-system add_subdirectory(System) + +# sfml-main and sfml-activity if(SFML_OS_WINDOWS OR SFML_OS_ANDROID OR SFML_OS_IOS) add_subdirectory(Main) endif() -add_subdirectory(Window) -add_subdirectory(Network) -add_subdirectory(Graphics) -add_subdirectory(Audio) + +# sfml-window +if(SFML_BUILD_WINDOW OR SFML_BUILD_GRAPHICS) + add_subdirectory(Window) +endif() + +# sfml-network +if(SFML_BUILD_NETWORK) + add_subdirectory(Network) +endif() + +# sfml-graphics +if(SFML_BUILD_GRAPHICS) + add_subdirectory(Graphics) +endif() + +# sfml-audio +if(SFML_BUILD_AUDIO) + add_subdirectory(Audio) +endif()