From a2fa3369de4df462af680e9ced3d54c7a36fc1e3 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Sun, 8 Mar 2015 23:59:06 +0800 Subject: [PATCH 01/27] Fix installation path of CMake package files --- CMakeLists.txt | 4 ++-- src/glfw3Config.cmake.in | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f0d66509..ed93fbb23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -479,7 +479,7 @@ endif() include(CMakePackageConfigHelpers) if (UNIX) - set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake/glfw3/") + set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/glfw3/") else() set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/") endif() @@ -532,7 +532,7 @@ if (GLFW_INSTALL) install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" - DESTINATION lib${LIB_SUFFIX}/cmake/glfw) + DESTINATION ${GLFW_CONFIG_PATH}) install(EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}/cmake/glfw) install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index d34df06f3..8e148a159 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -13,3 +13,4 @@ set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@" find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR}) +set(GLFW3_LIBRARIES "@GLFW_LIBRARIES@") From d9765be736d0031b986094655973061ef9543b5e Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 9 Mar 2015 00:11:33 +0800 Subject: [PATCH 02/27] Update glfw3Config.cmake.in --- src/glfw3Config.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index 8e148a159..3749c792c 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -13,4 +13,4 @@ set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@" find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR}) -set(GLFW3_LIBRARIES "@GLFW_LIBRARIES@") +set(GLFW_LIBRARIES "@GLFW_LIBRARIES@") From f42ada5ede177c7e06a73fc64ef23a521bb56073 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 9 Mar 2015 21:44:33 +0800 Subject: [PATCH 03/27] glfwTargets install directory --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed93fbb23..2b41a70cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,7 +534,7 @@ if (GLFW_INSTALL) "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION ${GLFW_CONFIG_PATH}) - install(EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}/cmake/glfw) + install(EXPORT glfwTargets DESTINATION ${GLFW_CONFIG_PATH}) install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) From 016d0e105f8d601a55a54abe59a5fc7d84ce89e6 Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Tue, 10 Mar 2015 23:41:55 -0400 Subject: [PATCH 04/27] Renames export targets file to glfw3Targets.cmake Normalize name so that all cmake configuration files share a common prefix of "glfw3". --- CMakeLists.txt | 4 +++- src/glfw3Config.cmake.in | 5 ++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b41a70cb..1d5eed408 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,7 +534,9 @@ if (GLFW_INSTALL) "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION ${GLFW_CONFIG_PATH}) - install(EXPORT glfwTargets DESTINATION ${GLFW_CONFIG_PATH}) + install(EXPORT glfwTargets FILE glfw3Targets.cmake + DESTINATION ${GLFW_CONFIG_PATH}) + install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" DESTINATION lib${LIB_SUFFIX}/pkgconfig) diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index 3749c792c..9ecc3b0a2 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -11,6 +11,5 @@ set(GLFW3_VERSION "@GLFW_VERSION_FULL@") set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/include") set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") -find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR}) - -set(GLFW_LIBRARIES "@GLFW_LIBRARIES@") +include("@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@/cmake/glfw/glfw3Targets.cmake") +set(GLFW3_LIBRARY glfw) From 6eeecb1b22a192b8167bd5fb8d2bba46679c6c53 Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Tue, 10 Mar 2015 23:54:39 -0400 Subject: [PATCH 05/27] Introduces install path variables. Adds variables for GLFW_INSTALL_{LIBRARY,INCLUDE,CONFIG,PKGCONFIG}_DIR, which enforces consistency between our install paths and paths exported via glfw3Config.cmake. --- CMakeLists.txt | 21 ++++++++++----------- src/glfw3Config.cmake.in | 6 +++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1d5eed408..41a962cdd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -478,19 +478,18 @@ endif() #-------------------------------------------------------------------- include(CMakePackageConfigHelpers) -if (UNIX) - set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}/cmake/glfw3/") -else() - set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/") -endif() +set(GLFW_INSTALL_INCLUDE_DIR "include") +set(GLFW_INSTALL_LIBRARY_DIR "lib${LIB_SUFFIX}") +set(GLFW_INSTALL_CONFIG_DIR "lib${LIB_SUFFIX}/cmake/glfw3") +set(GLFW_INSTALL_PKGCONFIG_DIR "lib${LIB_SUFFIX}/pkgconfig") configure_package_config_file("${GLFW_SOURCE_DIR}/src/glfw3Config.cmake.in" "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" - INSTALL_DESTINATION "${GLFW_CONFIG_PATH}" + INSTALL_DESTINATION "${GLFW_INSTALL_CONFIG_DIR}" PATH_VARS CMAKE_INSTALL_PREFIX NO_CHECK_REQUIRED_COMPONENTS_MACRO) -write_basic_package_version_file("${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" +write_basic_package_version_file("${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" VERSION ${GLFW_VERSION_FULL} COMPATIBILITY SameMajorVersion) @@ -527,18 +526,18 @@ endif() # The library is installed by src/CMakeLists.txt #-------------------------------------------------------------------- if (GLFW_INSTALL) - install(DIRECTORY include/GLFW DESTINATION include + install(DIRECTORY include/GLFW DESTINATION ${GLFW_INSTALL_INCLUDE_DIR} FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" - DESTINATION ${GLFW_CONFIG_PATH}) + DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) install(EXPORT glfwTargets FILE glfw3Targets.cmake - DESTINATION ${GLFW_CONFIG_PATH}) + DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" - DESTINATION lib${LIB_SUFFIX}/pkgconfig) + DESTINATION ${GLFW_INSTALL_PKGCONFIG_DIR}) # Only generate this target if no higher-level project already has if (NOT TARGET uninstall) diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index 9ecc3b0a2..36a8c14e4 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -8,8 +8,8 @@ set(GLFW3_VERSION "@GLFW_VERSION_FULL@") @PACKAGE_INIT@ -set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/include") -set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") +set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") +set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") -include("@PACKAGE_CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@/cmake/glfw/glfw3Targets.cmake") +include("@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_CONFIG_DIR@/glfw3Targets.cmake") set(GLFW3_LIBRARY glfw) From 168ad2a4b3bf4a6c81927df4821c180e10e9cd60 Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Tue, 10 Mar 2015 23:55:28 -0400 Subject: [PATCH 06/27] Export transitive dependencies Uses CMake 2.8.12 policy to export transitive interface libraries via glfw3Targets.cmake. This means we now link to dependent libraries (i.e. opengl32 on Win32) for free. --- CMakeLists.txt | 1 + src/CMakeLists.txt | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a962cdd..fc45be03e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,7 @@ project(GLFW C) cmake_minimum_required(VERSION 2.8.12) +cmake_policy(SET CMP0022 NEW) if (NOT CMAKE_VERSION VERSION_LESS "3.0") # Until all major package systems have moved to CMake 3, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 77a8501f6..91e6224ca 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -58,6 +58,7 @@ if (APPLE) endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) +target_link_libraries(glfw ${glfw_LIBRARIES}) set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}" VERSION ${GLFW_VERSION} @@ -86,8 +87,6 @@ if (BUILD_SHARED_LIBS) COMPILE_FLAGS "${glfw_CFLAGS} -fno-common" INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/lib${LIB_SUFFIX}") endif() - - target_link_libraries(glfw ${glfw_LIBRARIES}) endif() if (GLFW_INSTALL) From d2d89a8d80be14463fc0e5033aba54fe164b6870 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Wed, 11 Mar 2015 20:26:26 +0800 Subject: [PATCH 07/27] Added include directory to glfw target --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91e6224ca..c7375c021 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -90,6 +90,7 @@ if (BUILD_SHARED_LIBS) endif() if (GLFW_INSTALL) + target_include_directories(glfw PUBLIC ${CMAKE_INSTALL_PREFIX}/include) install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) endif() From 6297f916a6277682608de7d65996f313d146b512 Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Wed, 11 Mar 2015 17:56:40 -0400 Subject: [PATCH 08/27] Removes an absolute path from glfwTargets.cmake Invokes target_include_directories using generator expressions. The cmake package can now be relocated w/o error. --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7375c021..311ae1b59 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,6 +59,8 @@ endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) target_link_libraries(glfw ${glfw_LIBRARIES}) +target_include_directories(glfw PUBLIC $) + set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}" VERSION ${GLFW_VERSION} @@ -90,7 +92,6 @@ if (BUILD_SHARED_LIBS) endif() if (GLFW_INSTALL) - target_include_directories(glfw PUBLIC ${CMAKE_INSTALL_PREFIX}/include) install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) endif() From e2ff0645446caab8464952438d735d7879bd98a5 Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Wed, 11 Mar 2015 18:00:38 -0400 Subject: [PATCH 09/27] Conditionaly enables target_include_directories. CMake's target_include_directories breaks compatibility with glfw's minimum required version. The command is now if-guarded for CMake <2.8.11. --- src/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 311ae1b59..86229b464 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,7 +59,13 @@ endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) target_link_libraries(glfw ${glfw_LIBRARIES}) -target_include_directories(glfw PUBLIC $) +if (NOT CMAKE_VERSION VERSION_LESS "2.8.11") + # CMake 2.8.11 introduced the target_include_directories command to + # include and/or export public, private, and interface include + # directories. TODO If/when cmake_minimum_required increases to + # >=2.8.11, call this command unconditionally. + target_include_directories(glfw PUBLIC $) +endif() set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}" From f63d50977f33870adaad3379bc439bedfe28bf96 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Thu, 12 Mar 2015 11:11:57 +0800 Subject: [PATCH 10/27] Update build.dox --- docs/build.dox | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/docs/build.dox b/docs/build.dox index aa6c5fe80..f9265d75f 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -183,44 +183,25 @@ target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES}) @endcode -@subsection build_link_cmake_pkgconfig With CMake on Unix and installed GLFW binaries +@subsection build_link_cmake With CMake and installed GLFW binaries -CMake can import settings from pkg-config, which GLFW supports. When you -installed GLFW, the pkg-config file `glfw3.pc` was installed along with it. - -First you need to find the PkgConfig package. If this fails, you may need to -install the pkg-config package for your distribution. +CMake can import settings from CMake package file, which GLFW supports. @code{.cmake} -find_package(PkgConfig REQUIRED) +find_package(glfw3 REQUIRED) @endcode -This creates the CMake commands to find pkg-config packages. Then you need to -find the GLFW package. - -@code{.cmake} -pkg_search_module(GLFW REQUIRED glfw3) -@endcode - -This creates the CMake variables you need to use GLFW. To be able to include +This registers glfw imported target in your build. If you re using CMake < 2.8.11, to be able to include the GLFW header, you need to tell your compiler where it is. @code{.cmake} -include_directories(${GLFW_INCLUDE_DIRS}) +include_directories(${GLFW3_INCLUDE_DIR}) @endcode -You also need to link against the correct libraries. If you are using the -shared library version of GLFW, use the `GLFW_LIBRARIES` variable. +You need to link against glfw library and its transitive dependencies (platform-specific). @code{.cmake} -target_link_libraries(simple ${GLFW_LIBRARIES}) -@endcode - -If you are using the static library version of GLFW, use the -`GLFW_STATIC_LIBRARIES` variable instead. - -@code{.cmake} -target_link_libraries(simple ${GLFW_STATIC_LIBRARIES}) +target_link_libraries(simple ${GLFW3_LIBRARY}) @endcode From a89f9680ec33e872ebb26504fed9126bc9c131b2 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 6 Apr 2015 21:32:38 +0800 Subject: [PATCH 11/27] Fix CMake exports in build directory --- CMakeLists.txt | 4 ++++ src/CMakeLists.txt | 4 +++- src/glfw3Config.cmake.in | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fc45be03e..5bd1d3124 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -534,6 +534,10 @@ if (GLFW_INSTALL) "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) + export( + EXPORT glfwTargets + FILE ${CMAKE_CURRENT_BINARY_DIR}/src/glfw3Targets.cmake) + install(EXPORT glfwTargets FILE glfw3Targets.cmake DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 86229b464..f2061a5c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,7 +64,9 @@ if (NOT CMAKE_VERSION VERSION_LESS "2.8.11") # include and/or export public, private, and interface include # directories. TODO If/when cmake_minimum_required increases to # >=2.8.11, call this command unconditionally. - target_include_directories(glfw PUBLIC $) + target_include_directories(glfw PUBLIC + $ + $) endif() set_target_properties(glfw PROPERTIES diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index 36a8c14e4..420a3feae 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -11,5 +11,5 @@ set(GLFW3_VERSION "@GLFW_VERSION_FULL@") set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") -include("@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_CONFIG_DIR@/glfw3Targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") set(GLFW3_LIBRARY glfw) From 14c867d2c94d7c866df41c9e1c7ab5b5c5aea967 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Thu, 9 Apr 2015 11:19:21 +0800 Subject: [PATCH 12/27] Use GNUInstallDirs, enable build tree export --- CMakeLists.txt | 106 ++++++++++++++++++++++----------------- src/glfw3Config.cmake.in | 4 +- 2 files changed, 63 insertions(+), 47 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5bd1d3124..caf587f4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -474,37 +474,6 @@ else() set(GLFW_LIB_NAME glfw3) endif() -#-------------------------------------------------------------------- -# Create generated files -#-------------------------------------------------------------------- -include(CMakePackageConfigHelpers) - -set(GLFW_INSTALL_INCLUDE_DIR "include") -set(GLFW_INSTALL_LIBRARY_DIR "lib${LIB_SUFFIX}") -set(GLFW_INSTALL_CONFIG_DIR "lib${LIB_SUFFIX}/cmake/glfw3") -set(GLFW_INSTALL_PKGCONFIG_DIR "lib${LIB_SUFFIX}/pkgconfig") - -configure_package_config_file("${GLFW_SOURCE_DIR}/src/glfw3Config.cmake.in" - "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" - INSTALL_DESTINATION "${GLFW_INSTALL_CONFIG_DIR}" - PATH_VARS CMAKE_INSTALL_PREFIX - NO_CHECK_REQUIRED_COMPONENTS_MACRO) - -write_basic_package_version_file("${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" - VERSION ${GLFW_VERSION_FULL} - COMPATIBILITY SameMajorVersion) - -if (GLFW_BUILD_DOCS) - configure_file("${GLFW_SOURCE_DIR}/docs/Doxyfile.in" - "${GLFW_BINARY_DIR}/docs/Doxyfile" @ONLY) -endif() - -configure_file("${GLFW_SOURCE_DIR}/src/glfw_config.h.in" - "${GLFW_BINARY_DIR}/src/glfw_config.h" @ONLY) - -configure_file("${GLFW_SOURCE_DIR}/src/glfw3.pc.in" - "${GLFW_BINARY_DIR}/src/glfw3.pc" @ONLY) - #-------------------------------------------------------------------- # Add subdirectories #-------------------------------------------------------------------- @@ -522,32 +491,79 @@ if (DOXYGEN_FOUND AND GLFW_BUILD_DOCS) add_subdirectory(docs) endif() +#-------------------------------------------------------------------- +# Create generated files +#-------------------------------------------------------------------- +include(CMakePackageConfigHelpers) +include(GNUInstallDirs) + +set(GLFW_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3") +set(GLFW_INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") + +write_basic_package_version_file( + glfw3ConfigVersion.cmake + VERSION ${GLFW_VERSION_FULL} + COMPATIBILITY SameMajorVersion) + +# build tree package export +configure_package_config_file(src/glfw3Config.cmake.in + glfw3Config.cmake + INSTALL_DESTINATION ${GLFW_BINARY_DIR} + PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR + NO_CHECK_REQUIRED_COMPONENTS_MACRO) + +export( + EXPORT glfwTargets + FILE "${GLFW_BINARY_DIR}/glfw3Targets.cmake") + +export(PACKAGE glfw3) + +if (GLFW_BUILD_DOCS) + configure_file(docs/Doxyfile.in + docs/Doxyfile @ONLY) +endif() + +configure_file(src/glfw_config.h.in + src/glfw_config.h @ONLY) + +configure_file(src/glfw3.pc.in + src/glfw3.pc @ONLY) + #-------------------------------------------------------------------- # Install files other than the library # The library is installed by src/CMakeLists.txt #-------------------------------------------------------------------- if (GLFW_INSTALL) - install(DIRECTORY include/GLFW DESTINATION ${GLFW_INSTALL_INCLUDE_DIR} - FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) + configure_package_config_file(src/glfw3Config.cmake.in + ${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake + INSTALL_DESTINATION ${GLFW_INSTALL_CONFIG_DIR} + PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR + NO_CHECK_REQUIRED_COMPONENTS_MACRO) - install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" - "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" - DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) + install( + DIRECTORY include/GLFW + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} + FILES_MATCHING PATTERN *.h) - export( - EXPORT glfwTargets - FILE ${CMAKE_CURRENT_BINARY_DIR}/src/glfw3Targets.cmake) + install( + FILES + ${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake + glfw3ConfigVersion.cmake + DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) - install(EXPORT glfwTargets FILE glfw3Targets.cmake - DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) + install( + EXPORT glfwTargets + FILE glfw3Targets.cmake + DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) - install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" - DESTINATION ${GLFW_INSTALL_PKGCONFIG_DIR}) + install( + FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" + DESTINATION ${GLFW_INSTALL_PKGCONFIG_DIR}) # Only generate this target if no higher-level project already has if (NOT TARGET uninstall) - configure_file("${GLFW_SOURCE_DIR}/cmake_uninstall.cmake.in" - "${GLFW_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY) + configure_file(cmake_uninstall.cmake.in + cmake_uninstall.cmake IMMEDIATE @ONLY) add_custom_target(uninstall "${CMAKE_COMMAND}" -P diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in index 420a3feae..a5deb6727 100644 --- a/src/glfw3Config.cmake.in +++ b/src/glfw3Config.cmake.in @@ -8,8 +8,8 @@ set(GLFW3_VERSION "@GLFW_VERSION_FULL@") @PACKAGE_INIT@ -set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") -set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_PREFIX@/@GLFW_INSTALL_INCLUDE_DIR@") +set_and_check(GLFW3_INCLUDE_DIR "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") +set_and_check(GLFW3_LIBRARY_DIR "@PACKAGE_CMAKE_INSTALL_LIBDIR@") include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") set(GLFW3_LIBRARY glfw) From c38315ec69a1de519c1662649cb1802d0d382928 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Thu, 9 Apr 2015 23:59:23 +0800 Subject: [PATCH 13/27] Simplified build tree CMake config --- CMakeLists.txt | 7 +++---- src/glfw3BuildConfig.cmake.in | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) create mode 100644 src/glfw3BuildConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index caf587f4b..91f29b9f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -506,11 +506,10 @@ write_basic_package_version_file( COMPATIBILITY SameMajorVersion) # build tree package export -configure_package_config_file(src/glfw3Config.cmake.in +configure_file( + src/glfw3BuildConfig.cmake.in glfw3Config.cmake - INSTALL_DESTINATION ${GLFW_BINARY_DIR} - PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR - NO_CHECK_REQUIRED_COMPONENTS_MACRO) + COPYONLY) export( EXPORT glfwTargets diff --git a/src/glfw3BuildConfig.cmake.in b/src/glfw3BuildConfig.cmake.in new file mode 100644 index 000000000..1fa200e27 --- /dev/null +++ b/src/glfw3BuildConfig.cmake.in @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/glfw3Targets.cmake") From 566108d35a0285c7cc236ac892caa3f7678fcba4 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Mon, 8 Jun 2015 15:21:18 +0200 Subject: [PATCH 14/27] fix: some install(FILES..) assumed GLFW_BINARY_DIR --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 91f29b9f0..c391fd11f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -546,8 +546,8 @@ if (GLFW_INSTALL) install( FILES - ${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake - glfw3ConfigVersion.cmake + ${GLFW_BINARY_DIR}/${GLFW_INSTALL_CONFIG_DIR}/glfw3Config.cmake + ${GLFW_BINARY_DIR}/glfw3ConfigVersion.cmake DESTINATION ${GLFW_INSTALL_CONFIG_DIR}) install( From 6ed81bb33cc6ab8616f9460632954d8bbd504616 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Thu, 18 Jun 2015 01:04:04 +0200 Subject: [PATCH 15/27] cmake: fix exported include dir path target_include_directories used GLFW_INSTALL_INCLUDE_DIR which was undefined. The correct variable is CMAKE_INSTALL_INCLUDEDIR which is what the installer sections use. --- CMakeLists.txt | 3 ++- src/CMakeLists.txt | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c391fd11f..50f5528c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,6 +477,8 @@ endif() #-------------------------------------------------------------------- # Add subdirectories #-------------------------------------------------------------------- +include(GNUInstallDirs) + add_subdirectory(src) if (GLFW_BUILD_EXAMPLES) @@ -495,7 +497,6 @@ endif() # Create generated files #-------------------------------------------------------------------- include(CMakePackageConfigHelpers) -include(GNUInstallDirs) set(GLFW_INSTALL_CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3") set(GLFW_INSTALL_PKGCONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/pkgconfig") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f2061a5c4..cf879bca8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -65,7 +65,7 @@ if (NOT CMAKE_VERSION VERSION_LESS "2.8.11") # directories. TODO If/when cmake_minimum_required increases to # >=2.8.11, call this command unconditionally. target_include_directories(glfw PUBLIC - $ + $ $) endif() From fc869d11007d3181a06b372bbb06a3354ba5289d Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Thu, 23 Jul 2015 13:30:43 +0800 Subject: [PATCH 16/27] Remove package export --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50f5528c9..cef157ac9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -516,8 +516,6 @@ export( EXPORT glfwTargets FILE "${GLFW_BINARY_DIR}/glfw3Targets.cmake") -export(PACKAGE glfw3) - if (GLFW_BUILD_DOCS) configure_file(docs/Doxyfile.in docs/Doxyfile @ONLY) From e990a200002ae465d829fef5e6952931fae21461 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Mon, 29 Jun 2015 15:24:40 +0200 Subject: [PATCH 17/27] build: add DEBUG_POSTFIX 'd' --- src/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cf879bca8..f1e0f4ae9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -74,7 +74,8 @@ set_target_properties(glfw PROPERTIES VERSION ${GLFW_VERSION} SOVERSION ${GLFW_VERSION_MAJOR} POSITION_INDEPENDENT_CODE ON - FOLDER "GLFW3") + FOLDER "GLFW3" + DEBUG_POSTFIX d) if (BUILD_SHARED_LIBS) if (WIN32) From 38c91bc9387f8aac5bbd15e3cf6595bde8db642a Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Sun, 4 Oct 2015 19:16:00 +0800 Subject: [PATCH 18/27] Travis CI configuration --- .travis.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..6543ea3c5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,12 @@ +sudo: false +addons: + apt: + sources: + - kubuntu-backports + packages: + - cmake +script: + - mkdir build + - cd build + - cmake .. + - make From 60121fb0a9d2fda6cf7ad690ff94b027021b1ad5 Mon Sep 17 00:00:00 2001 From: Tamas Kenez Date: Sat, 3 Oct 2015 12:11:28 +0200 Subject: [PATCH 19/27] cmake: use export(EXPORT ..) only if CMake >= 3.0 --- CMakeLists.txt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cef157ac9..c73783521 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,9 +512,11 @@ configure_file( glfw3Config.cmake COPYONLY) -export( - EXPORT glfwTargets - FILE "${GLFW_BINARY_DIR}/glfw3Targets.cmake") +if(NOT CMAKE_VERSION VERSION_LESS 3.0) + export( + EXPORT glfwTargets + FILE "${GLFW_BINARY_DIR}/glfw3Targets.cmake") +endif() if (GLFW_BUILD_DOCS) configure_file(docs/Doxyfile.in From 6eb7c7d6a03aeb6f98ac4ec3f2ea9ad1fe57b29d Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 00:10:34 +0800 Subject: [PATCH 20/27] Travis CI: Set language and operating systems --- .travis.yml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6543ea3c5..f078189fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,9 @@ +language: cpp + +os: + - linux + - osx + sudo: false addons: apt: @@ -6,7 +12,5 @@ addons: packages: - cmake script: - - mkdir build - - cd build - - cmake .. + - cmake . - make From 8117f78a2350fc81c9835fa1e28b217211e4f256 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 01:12:04 +0800 Subject: [PATCH 21/27] Remove CMake <2.8.12 declarations --- docs/build.dox | 8 +------- src/CMakeLists.txt | 12 +++--------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/docs/build.dox b/docs/build.dox index f9265d75f..bf635fc6e 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -191,13 +191,7 @@ CMake can import settings from CMake package file, which GLFW supports. find_package(glfw3 REQUIRED) @endcode -This registers glfw imported target in your build. If you re using CMake < 2.8.11, to be able to include -the GLFW header, you need to tell your compiler where it is. - -@code{.cmake} -include_directories(${GLFW3_INCLUDE_DIR}) -@endcode - +This registers glfw imported target in your build. You need to link against glfw library and its transitive dependencies (platform-specific). @code{.cmake} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f1e0f4ae9..37a762c78 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -59,15 +59,9 @@ endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) target_link_libraries(glfw ${glfw_LIBRARIES}) -if (NOT CMAKE_VERSION VERSION_LESS "2.8.11") - # CMake 2.8.11 introduced the target_include_directories command to - # include and/or export public, private, and interface include - # directories. TODO If/when cmake_minimum_required increases to - # >=2.8.11, call this command unconditionally. - target_include_directories(glfw PUBLIC - $ - $) -endif() +target_include_directories(glfw PUBLIC + $ + $) set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}" From ba2c5a7d068b389623eba6525431236f688c0102 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 05:19:57 +0800 Subject: [PATCH 22/27] Windows build --- .travis.yml | 2 +- appveyor.yml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml index f078189fc..6f915aa37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,4 +13,4 @@ addons: - cmake script: - cmake . - - make + - cmake --build . diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 000000000..e8b191f11 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,3 @@ +build_script: + - cmake . + - cmake --build . From 97fd691183a1ca776e13115703d4b4109fd0096e Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 05:38:37 +0800 Subject: [PATCH 23/27] Modernize src and examples CMake build files --- examples/CMakeLists.txt | 13 +------------ src/CMakeLists.txt | 20 +++++++++----------- tests/CMakeLists.txt | 12 +----------- 3 files changed, 11 insertions(+), 34 deletions(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 16a25b0fd..f66897283 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,15 +1,5 @@ - link_libraries(glfw) - -if (BUILD_SHARED_LIBS) - add_definitions(-DGLFW_DLL) - link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}") -else() - link_libraries(${glfw_LIBRARIES}) -endif() - -include_directories("${GLFW_SOURCE_DIR}/include" - "${GLFW_SOURCE_DIR}/deps") +include_directories(${GLFW_SOURCE_DIR}/deps) if ("${OPENGL_INCLUDE_DIR}") include_directories("${OPENGL_INCLUDE_DIR}") @@ -56,4 +46,3 @@ if (APPLE) MACOSX_BUNDLE_LONG_VERSION_STRING ${GLFW_VERSION_FULL} MACOSX_BUNDLE_INFO_PLIST "${GLFW_SOURCE_DIR}/CMake/MacOSXBundleInfo.plist.in") endif() - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 37a762c78..cfc3439b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,3 @@ - -include_directories("${GLFW_SOURCE_DIR}/src" - "${GLFW_BINARY_DIR}/src" - ${glfw_INCLUDE_DIRS}) - -add_definitions(-D_GLFW_USE_CONFIG_H) - set(common_HEADERS internal.h "${GLFW_BINARY_DIR}/src/glfw_config.h" "${GLFW_SOURCE_DIR}/include/GLFW/glfw3.h" @@ -59,9 +52,15 @@ endif() add_library(glfw ${glfw_SOURCES} ${glfw_HEADERS}) target_link_libraries(glfw ${glfw_LIBRARIES}) -target_include_directories(glfw PUBLIC - $ - $) +target_include_directories(glfw + PUBLIC + $ + $ + PRIVATE + "${GLFW_SOURCE_DIR}/src" + "${GLFW_BINARY_DIR}/src" + ${glfw_INCLUDE_DIRS}) +target_compile_definitions(glfw PRIVATE -D_GLFW_USE_CONFIG_H) set_target_properties(glfw PROPERTIES OUTPUT_NAME "${GLFW_LIB_NAME}" @@ -97,4 +96,3 @@ endif() if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}) endif() - diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bfc67d83d..ffd87943d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,15 +1,5 @@ - link_libraries(glfw) - -if (BUILD_SHARED_LIBS) - add_definitions(-DGLFW_DLL) - link_libraries("${OPENGL_gl_LIBRARY}" "${MATH_LIBRARY}") -else() - link_libraries(${glfw_LIBRARIES}) -endif() - -include_directories("${GLFW_SOURCE_DIR}/include" - "${GLFW_SOURCE_DIR}/deps") +include_directories(${GLFW_SOURCE_DIR}/deps) if ("${OPENGL_INCLUDE_DIR}") include_directories("${OPENGL_INCLUDE_DIR}") From cd373545b04ba0f7c89812ed688cfdefd2cc753c Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 05:52:05 +0800 Subject: [PATCH 24/27] Setup shared/static Travis and AppVeyor build --- .travis.yml | 7 ++++--- appveyor.yml | 6 +++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6f915aa37..e19a79f7b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,10 @@ language: cpp - os: - linux - osx - +env: + - BUILD_SHARED_LIBS=ON + - BUILD_SHARED_LIBS=OFF sudo: false addons: apt: @@ -12,5 +13,5 @@ addons: packages: - cmake script: - - cmake . + - cmake -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} . - cmake --build . diff --git a/appveyor.yml b/appveyor.yml index e8b191f11..d65f58816 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,3 +1,7 @@ +environment: + matrix: + - BUILD_SHARED_LIBS: ON + - BUILD_SHARED_LIBS: OFF build_script: - - cmake . + - cmake -DBUILD_SHARED_LIBS=%BUILD_SHARED_LIBS% . - cmake --build . From ccd7ec01200d781e4c4ce9afb563df5fbe19a084 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 14:46:34 +0800 Subject: [PATCH 25/27] Include GLFW_DLL in interface definitions --- src/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index cfc3439b8..5443b61b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -72,6 +72,7 @@ set_target_properties(glfw PROPERTIES if (BUILD_SHARED_LIBS) if (WIN32) + target_compile_definitions(glfw INTERFACE -DGLFW_DLL) # The GLFW DLL needs a special compile-time macro and import library name set_target_properties(glfw PROPERTIES PREFIX "" IMPORT_PREFIX "") From d022855f54a555382a29621fb2dd8532f4605971 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Mon, 5 Oct 2015 20:40:42 +0800 Subject: [PATCH 26/27] Update build documentation with new CMake linking --- docs/build.dox | 69 ++++++++++++++++++++++++++++++++--------- examples/CMakeLists.txt | 4 --- tests/CMakeLists.txt | 4 --- 3 files changed, 55 insertions(+), 22 deletions(-) diff --git a/docs/build.dox b/docs/build.dox index bf635fc6e..1902c15d0 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -58,7 +58,7 @@ either be included _before_ the GLFW one, or the `GLFW_INCLUDE_NONE` macro These macros may be defined before the inclusion of the GLFW header and affect its behavior. -`GLFW_DLL` is required on Windows when using the GLFW DLL, to tell the compiler +`GLFW_DLL` is required on Windows (GLFW before 3.2) when using the GLFW DLL, to tell the compiler that the GLFW functions are defined in a DLL. The following macros control which OpenGL or OpenGL ES API header is included. @@ -165,24 +165,20 @@ compiler where to find it. include_directories(path/to/glfw/include) @endcode -Once GLFW has been added to the project, the `GLFW_LIBRARIES` cache variable -contains all link-time dependencies of GLFW as it is currently configured. To -link against GLFW, link against them and the `glfw` target. - +You need to link against glfw library and its transitive dependencies. @code{.cmake} -target_link_libraries(myapp glfw ${GLFW_LIBRARIES}) +target_link_libraries(myapp glfw) @endcode -Note that `GLFW_LIBRARIES` does not include GLU, as GLFW does not use it. If -your application needs GLU, you can add it to the list of dependencies with the -`OPENGL_glu_LIBRARY` cache variable, which is implicitly created when the GLFW -CMake files look for OpenGL. +Note that glfw transitive dependencies do not include GLU, as GLFW does not use +it. If your application needs GLU, you can add it to the list of dependencies +with the `OPENGL_glu_LIBRARY` cache variable, which is implicitly created when +the GLFW CMake files look for OpenGL. @code{.cmake} -target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES}) +target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY}) @endcode - @subsection build_link_cmake With CMake and installed GLFW binaries CMake can import settings from CMake package file, which GLFW supports. @@ -192,15 +188,60 @@ find_package(glfw3 REQUIRED) @endcode This registers glfw imported target in your build. -You need to link against glfw library and its transitive dependencies (platform-specific). +You need to link against glfw library and its transitive dependencies. @code{.cmake} -target_link_libraries(simple ${GLFW3_LIBRARY}) +target_link_libraries(simple glfw) @endcode +@subsection build_link_cmake_pkgconfig With CMake on Unix and installed GLFW binaries + +@deprecated Since GLFW 3.2 it is recommended to use @ref build_link_cmake +"native CMake configuration files" + +CMake can import settings from pkg-config, which GLFW supports. When you +installed GLFW, the pkg-config file `glfw3.pc` was installed along with it. + +First you need to find the PkgConfig package. If this fails, you may need to +install the pkg-config package for your distribution. + +@code{.cmake} +find_package(PkgConfig REQUIRED) +@endcode + +This creates the CMake commands to find pkg-config packages. Then you need to +find the GLFW package. + +@code{.cmake} +pkg_search_module(GLFW REQUIRED glfw3) +@endcode + +This creates the CMake variables you need to use GLFW. To be able to include +the GLFW header, you need to tell your compiler where it is. + +@code{.cmake} +include_directories(${GLFW_INCLUDE_DIRS}) +@endcode + +You also need to link against the correct libraries. If you are using the +shared library version of GLFW, use the `GLFW_LIBRARIES` variable. + +@code{.cmake} +target_link_libraries(simple ${GLFW_LIBRARIES}) +@endcode + +If you are using the static library version of GLFW, use the +`GLFW_STATIC_LIBRARIES` variable instead. + +@code{.cmake} +target_link_libraries(simple ${GLFW_STATIC_LIBRARIES}) +@endcode @subsection build_link_pkgconfig With pkg-config on OS X or other Unix +@deprecated Since GLFW 3.2 it is recommended to use @ref build_link_cmake +"native CMake configuration files" + GLFW supports [pkg-config](http://www.freedesktop.org/wiki/Software/pkg-config/), and the `glfw3.pc` pkf-config file is generated when the GLFW library is built and is installed along with it. A pkg-config file describes all necessary diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index f66897283..c2ba2f7a4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,10 +1,6 @@ link_libraries(glfw) include_directories(${GLFW_SOURCE_DIR}/deps) -if ("${OPENGL_INCLUDE_DIR}") - include_directories("${OPENGL_INCLUDE_DIR}") -endif() - set(GLAD "${GLFW_SOURCE_DIR}/deps/glad/glad.h" "${GLFW_SOURCE_DIR}/deps/glad.c") set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ffd87943d..9d0844d0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,10 +1,6 @@ link_libraries(glfw) include_directories(${GLFW_SOURCE_DIR}/deps) -if ("${OPENGL_INCLUDE_DIR}") - include_directories("${OPENGL_INCLUDE_DIR}") -endif() - set(GETOPT "${GLFW_SOURCE_DIR}/deps/getopt.h" "${GLFW_SOURCE_DIR}/deps/getopt.c") set(TINYCTHREAD "${GLFW_SOURCE_DIR}/deps/tinycthread.h" From 2f59dadb0c4e8d0b95076daf8ac4fd3053bbdf58 Mon Sep 17 00:00:00 2001 From: Zbigniew Mandziejewicz Date: Thu, 8 Oct 2015 00:22:37 +0800 Subject: [PATCH 27/27] Remove 3.0 dependendent target export in build tree --- CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c73783521..0092d6a1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -512,11 +512,9 @@ configure_file( glfw3Config.cmake COPYONLY) -if(NOT CMAKE_VERSION VERSION_LESS 3.0) - export( - EXPORT glfwTargets - FILE "${GLFW_BINARY_DIR}/glfw3Targets.cmake") -endif() +export( + TARGETS glfw + FILE glfw3Targets.cmake) if (GLFW_BUILD_DOCS) configure_file(docs/Doxyfile.in