From fe7a4eb4ffc3512834488e5366c31fd1489860c4 Mon Sep 17 00:00:00 2001 From: Camilla Berglund Date: Mon, 5 Jan 2015 02:40:32 +0100 Subject: [PATCH] Improved CMake config file generation. --- .gitignore | 4 ++-- CMakeLists.txt | 28 ++++++++++++++++++++-------- src/glfw3Config.cmake.in | 15 +++++++++++++++ src/glfwConfig.cmake.in | 10 ---------- src/glfwConfigVersion.cmake.in | 12 ------------ 5 files changed, 37 insertions(+), 32 deletions(-) create mode 100644 src/glfw3Config.cmake.in delete mode 100644 src/glfwConfig.cmake.in delete mode 100644 src/glfwConfigVersion.cmake.in diff --git a/.gitignore b/.gitignore index 3e206b4a..49779f1e 100644 --- a/.gitignore +++ b/.gitignore @@ -23,8 +23,8 @@ docs/html docs/warnings.txt src/glfw_config.h src/glfw3.pc -src/glfwConfig.cmake -src/glfwConfigVersion.cmake +src/glfw3Config.cmake +src/glfw3ConfigVersion.cmake # Compiled binaries src/libglfw.so diff --git a/CMakeLists.txt b/CMakeLists.txt index 077e5736..a17dd508 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -509,6 +509,24 @@ endif() #-------------------------------------------------------------------- # Create generated files #-------------------------------------------------------------------- +include(CMakePackageConfigHelpers) + +if (UNIX) + set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/lib/cmake/glfw3/") +else() + set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_PREFIX}/") +endif() + +configure_package_config_file("${GLFW_SOURCE_DIR}/src/glfw3Config.cmake.in" + "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" + INSTALL_DESTINATION "${GLFW_CONFIG_PATH}" + 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) @@ -517,12 +535,6 @@ 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/glfwConfig.cmake.in" - "${GLFW_BINARY_DIR}/src/glfwConfig.cmake" @ONLY) - -configure_file("${GLFW_SOURCE_DIR}/src/glfwConfigVersion.cmake.in" - "${GLFW_BINARY_DIR}/src/glfwConfigVersion.cmake" @ONLY) - configure_file("${GLFW_SOURCE_DIR}/src/glfw3.pc.in" "${GLFW_BINARY_DIR}/src/glfw3.pc" @ONLY) @@ -551,8 +563,8 @@ if (GLFW_INSTALL) install(DIRECTORY include/GLFW DESTINATION include FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) - install(FILES "${GLFW_BINARY_DIR}/src/glfwConfig.cmake" - "${GLFW_BINARY_DIR}/src/glfwConfigVersion.cmake" + install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" + "${GLFW_BINARY_DIR}/src/glfw3ConfigVersion.cmake" DESTINATION lib${LIB_SUFFIX}/cmake/glfw) install(EXPORT glfwTargets DESTINATION lib${LIB_SUFFIX}/cmake/glfw) diff --git a/src/glfw3Config.cmake.in b/src/glfw3Config.cmake.in new file mode 100644 index 00000000..d34df06f --- /dev/null +++ b/src/glfw3Config.cmake.in @@ -0,0 +1,15 @@ +# - Config file for the glfw3 package +# It defines the following variables +# GLFW3_INCLUDE_DIR, the path where GLFW headers are located +# GLFW3_LIBRARY_DIR, folder in which the GLFW library is located +# GLFW3_LIBRARY, library to link against to use GLFW + +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@") + +find_library(GLFW3_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW3_LIBRARY_DIR}) + diff --git a/src/glfwConfig.cmake.in b/src/glfwConfig.cmake.in deleted file mode 100644 index 796ad2ca..00000000 --- a/src/glfwConfig.cmake.in +++ /dev/null @@ -1,10 +0,0 @@ -# - Config file for the glfw package -# It defines the following variables -# GLFW_INCLUDE_DIR, the path where GLFW headers are located -# GLFW_LIBRARY_DIR, folder in which the GLFW library is located -# GLFW_LIBRARY, library to link against to use GLFW - -set(GLFW_INCLUDE_DIR "@CMAKE_INSTALL_PREFIX@/include") -set(GLFW_LIBRARY_DIR "@CMAKE_INSTALL_PREFIX@/lib@LIB_SUFFIX@") - -find_library(GLFW_LIBRARY "@GLFW_LIB_NAME@" HINTS ${GLFW_LIBRARY_DIR}) diff --git a/src/glfwConfigVersion.cmake.in b/src/glfwConfigVersion.cmake.in deleted file mode 100644 index da8eaf6d..00000000 --- a/src/glfwConfigVersion.cmake.in +++ /dev/null @@ -1,12 +0,0 @@ - -set(PACKAGE_VERSION "@GLFW_VERSION_FULL@") - -if ("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL "@GLFW_VERSION_MAJOR@") - set(PACKAGE_VERSION_COMPATIBLE TRUE) - if ("${PACKAGE_FIND_VERSION_MINOR}" EQUAL @GLFW_VERSION_MINOR@) - set(PACKAGE_VERSION_EXACT TRUE) - endif() -else() - set(PACKAGE_VERSION_COMPATIBLE FALSE) -endif() -