diff --git a/CMakeLists.txt b/CMakeLists.txt index c1fb6a375..c579058fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,11 +73,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_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) @@ -135,6 +145,12 @@ if(NOT BUILD_SHARED_LIBS) add_definitions(-DSFML_STATIC) 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 # (except for stb_image) # yes this is horrible, but GLOB_RECURSE sucks @@ -231,15 +247,39 @@ 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() +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 set_property(GLOBAL PROPERTY USE_FOLDERS ON) set_property(GLOBAL PROPERTY PREDEFINED_TARGETS_FOLDER "CMake") @@ -306,10 +346,46 @@ else() MACOSX_FRAMEWORK_BUNDLE_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH} PUBLIC_HEADER "${SFML_HEADERS}") - # add the remaining headers - add_custom_command(TARGET SFML - POST_BUILD - COMMAND cp -r ${PROJECT_SOURCE_DIR}/include/SFML/* $/Headers) + # add the non-optional SFML headers + add_custom_command(TARGET SFML POST_BUILD COMMAND cp -r + ${PROJECT_SOURCE_DIR}/include/SFML/Config.hpp + ${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 + $/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 + $/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 + $/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 + $/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 + $/Headers) + endif() # adapt install directory to allow distributing dylibs/frameworks in user's frameworks/application bundle # NOTE: it's not required to link against SFML.framework @@ -356,32 +432,36 @@ 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") - install(DIRECTORY extlibs/libs-osx/Frameworks/FLAC.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("${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() + 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}) + 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}) - 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}) + endif() - 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(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") - install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisenc.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + 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") - install(DIRECTORY extlibs/libs-osx/Frameworks/vorbisfile.framework DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) - endif() + 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") - install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + if(OPENAL_LIBRARY STREQUAL "${SFML_SOURCE_DIR}/extlibs/libs-osx/Frameworks/OpenAL.framework") + install(DIRECTORY "${OPENAL_LIBRARY}" DESTINATION ${CMAKE_INSTALL_FRAMEWORK_PREFIX}) + endif() endif() # install the Xcode templates if requested @@ -408,7 +488,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 a55137d64..872c77d9c 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 8eb334d95..61be9ae6a 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()