From f9923e90958e726aaabc86d83fb3681216d76067 Mon Sep 17 00:00:00 2001 From: Rolf Eike Beer Date: Tue, 30 Oct 2018 13:30:44 +0100 Subject: [PATCH] Use GNUInstallDirs for install destinations This has the advantage that the user may override e.g. the include location, and the correct libdir (lib, lib64, lib/something) is automatically determined. Closes #1367. --- CMakeLists.txt | 9 +++++---- docs/compile.dox | 5 ----- src/CMakeLists.txt | 10 +++++----- src/glfw3.pc.in | 4 ++-- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f40852e..41416296 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,6 @@ set(GLFW_VERSION_PATCH "0") set(GLFW_VERSION_EXTRA "") set(GLFW_VERSION "${GLFW_VERSION_MAJOR}.${GLFW_VERSION_MINOR}") set(GLFW_VERSION_FULL "${GLFW_VERSION}.${GLFW_VERSION_PATCH}${GLFW_VERSION_EXTRA}") -set(LIB_SUFFIX "" CACHE STRING "Takes an empty string or 64. Directory where lib will be installed: lib or lib64") set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -25,6 +24,8 @@ option(GLFW_BUILD_DOCS "Build the GLFW documentation" ON) option(GLFW_INSTALL "Generate installation target" ON) option(GLFW_VULKAN_STATIC "Use the Vulkan loader statically linked into application" OFF) +include(GNUInstallDirs) + if (UNIX) option(GLFW_USE_OSMESA "Use OSMesa for offscreen context creation" OFF) endif() @@ -320,7 +321,7 @@ endforeach() #-------------------------------------------------------------------- include(CMakePackageConfigHelpers) -set(GLFW_CONFIG_PATH "lib${LIB_SUFFIX}/cmake/glfw3") +set(GLFW_CONFIG_PATH "${CMAKE_INSTALL_LIBDIR}/cmake/glfw3") configure_package_config_file(src/glfw3Config.cmake.in src/glfw3Config.cmake @@ -357,7 +358,7 @@ endif() # The library is installed by src/CMakeLists.txt #-------------------------------------------------------------------- if (GLFW_INSTALL) - install(DIRECTORY include/GLFW DESTINATION include + install(DIRECTORY include/GLFW DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING PATTERN glfw3.h PATTERN glfw3native.h) install(FILES "${GLFW_BINARY_DIR}/src/glfw3Config.cmake" @@ -368,7 +369,7 @@ if (GLFW_INSTALL) EXPORT_LINK_INTERFACE_LIBRARIES DESTINATION "${GLFW_CONFIG_PATH}") install(FILES "${GLFW_BINARY_DIR}/src/glfw3.pc" - DESTINATION "lib${LIB_SUFFIX}/pkgconfig") + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") # Only generate this target if no higher-level project already has if (NOT TARGET uninstall) diff --git a/docs/compile.dox b/docs/compile.dox index d2133e94..e03b74aa 100644 --- a/docs/compile.dox +++ b/docs/compile.dox @@ -210,11 +210,6 @@ cmake -DBUILD_SHARED_LIBS=ON . __BUILD_SHARED_LIBS__ determines whether GLFW is built as a static library or as a DLL / shared library / dynamic library. -@anchor LIB_SUFFIX -__LIB_SUFFIX__ affects where the GLFW shared /dynamic library is installed. If -it is empty, it is installed to `${CMAKE_INSTALL_PREFIX}/lib`. If it is set to -`64`, it is installed to `${CMAKE_INSTALL_PREFIX}/lib64`. - @anchor GLFW_BUILD_EXAMPLES __GLFW_BUILD_EXAMPLES__ determines whether the GLFW examples are built along with the library. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ecce1706..6bf4ff0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,7 +100,7 @@ set_target_properties(glfw PROPERTIES target_compile_definitions(glfw PRIVATE _GLFW_USE_CONFIG_H) target_include_directories(glfw PUBLIC "$" - "$/include>") + "$") target_include_directories(glfw PRIVATE "${GLFW_SOURCE_DIR}/src" "${GLFW_BINARY_DIR}/src" @@ -121,7 +121,7 @@ target_compile_options(glfw PRIVATE if (BUILD_SHARED_LIBS) if (WIN32) if (MINGW) - # Remove the lib prefix on the DLL (but not the import library + # Remove the lib prefix on the DLL (but not the import library) set_target_properties(glfw PROPERTIES PREFIX "") # Add a suffix to the import library to avoid naming conflicts @@ -135,7 +135,7 @@ if (BUILD_SHARED_LIBS) target_compile_options(glfw PRIVATE "-fno-common") set_target_properties(glfw PROPERTIES - INSTALL_NAME_DIR "lib${LIB_SUFFIX}") + INSTALL_NAME_DIR "${CMAKE_INSTALL_LIBDIR}") elseif (UNIX) # Hide symbols not explicitly tagged for export from the shared library target_compile_options(glfw PRIVATE "-fvisibility=hidden") @@ -155,7 +155,7 @@ if (GLFW_INSTALL) install(TARGETS glfw EXPORT glfwTargets RUNTIME DESTINATION "bin" - ARCHIVE DESTINATION "lib${LIB_SUFFIX}" - LIBRARY DESTINATION "lib${LIB_SUFFIX}") + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") endif() diff --git a/src/glfw3.pc.in b/src/glfw3.pc.in index 9feaa80e..87423e1a 100644 --- a/src/glfw3.pc.in +++ b/src/glfw3.pc.in @@ -1,7 +1,7 @@ prefix=@CMAKE_INSTALL_PREFIX@ exec_prefix=${prefix} -includedir=${prefix}/include -libdir=${exec_prefix}/lib@LIB_SUFFIX@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ +libdir=@CMAKE_INSTALL_FULL_LIBDIR@ Name: GLFW Description: A multi-platform library for OpenGL, window and input