From 8ee589e43bcca6e4e3517f245996b73ebdc194eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Wed, 8 May 2019 19:04:21 +0200 Subject: [PATCH] Disable examples and tests when a subproject This changes the default value of the GLFW_BUILD_EXAMPLES and GLFW_BUILD_TESTS CMake options to false when GLFW is being added as a subdirectory by another CMake project. If you want the previous behavior, force these options to true before adding the GLFW subdirectory: set(GLFW_BUILD_EXAMPLES ON CACHE BOOL "" FORCE) set(GLFW_BUILD_TESTS ON CACHE BOOL "" FORCE) add_subdirectory(path/to/glfw) Doing this is backward compatible with earlier versions of GLFW. The GLFW_BUILD_DOCS option is left enabled as it also requires Doxygen to have any effect, is quicker to build and is more likely to be useful when GLFW is a subproject. --- CMakeLists.txt | 8 ++++++-- README.md | 1 + docs/build.dox | 14 ++------------ docs/compile.dox | 6 ++++-- docs/news.dox | 14 ++++++++++++++ 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6b6aab0..e393a144 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,9 +10,13 @@ endif() set_property(GLOBAL PROPERTY USE_FOLDERS ON) +if ("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}") + set(GLFW_STANDALONE TRUE) +endif() + option(BUILD_SHARED_LIBS "Build shared libraries" OFF) -option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" ON) -option(GLFW_BUILD_TESTS "Build the GLFW test programs" ON) +option(GLFW_BUILD_EXAMPLES "Build the GLFW example programs" GLFW_STANDALONE) +option(GLFW_BUILD_TESTS "Build the GLFW test programs" GLFW_STANDALONE) option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) option(GLFW_INSTALL "Generate installation target" ON) option(GLFW_VULKAN_STATIC "Assume the Vulkan loader is linked with the application" OFF) diff --git a/README.md b/README.md index 3277985c..78523eeb 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ information on what to include when reporting a bug. ## Changelog + - Disabled tests and examples by default when built as a CMake subdirectory - Bugfix: The CMake config-file package used an absolute path and was not relocatable (#1470) - [X11] Bugfix: The CMake files did not check for the XInput headers (#1480) diff --git a/docs/build.dox b/docs/build.dox index 6e8f11f9..127c9f06 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -186,18 +186,8 @@ build_link_cmake_package. With a few changes to your `CMakeLists.txt` you can have the GLFW source tree built along with your application. -When including GLFW as part of your build, you probably don't want to build the -GLFW tests, examples and documentation. To disable these, set the corresponding -cache variables before adding the GLFW source tree. - -@code -set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE) -set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) -@endcode - -Then add the root directory of the GLFW source tree to your project. This -will add the `glfw` target and the necessary cache variables to your project. +Add the root directory of the GLFW source tree to your project. This will add +the `glfw` target and the necessary cache variables to your project. @code{.cmake} add_subdirectory(path/to/glfw) diff --git a/docs/compile.dox b/docs/compile.dox index 8a4fb583..271cee4d 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -212,11 +212,13 @@ library or as a DLL / shared library / dynamic library. @anchor GLFW_BUILD_EXAMPLES __GLFW_BUILD_EXAMPLES__ determines whether the GLFW examples are built -along with the library. +along with the library. This is enabled by default unless GLFW is being built +as a sub-project. @anchor GLFW_BUILD_TESTS __GLFW_BUILD_TESTS__ determines whether the GLFW test programs are -built along with the library. +built along with the library. This is enabled by default unless GLFW is being +built as a sub-project. @anchor GLFW_BUILD_DOCS __GLFW_BUILD_DOCS__ determines whether the GLFW documentation is built along diff --git a/docs/news.dox b/docs/news.dox index 1e322ca3..f551bb94 100644 --- a/docs/news.dox +++ b/docs/news.dox @@ -11,6 +11,20 @@ @subsection caveats_34 Caveats for version 3.4 +@subsubsection standalone_34 Tests and examples are disabled when built as a sub-project + +GLFW now does not build the tests and examples when it is added as +a subdirectory of another CMake project. To enable these, set the @ref +GLFW_BUILD_TESTS and @ref GLFW_BUILD_EXAMPLES cache variables before adding the +GLFW subdirectory. + +@code{.cmake} +set(GLFW_BUILD_EXAMPLES ON CACHE BOOL "" FORCE) +set(GLFW_BUILD_TESTS ON CACHE BOOL "" FORCE) +add_subdirectory(path/to/glfw) +@endcode + + @subsection deprecations_34 Deprecations in version 3.4 @subsection removals_34 Removals in 3.4