From 453631773ee7f678f0a2b19961a5f0e8125619ef Mon Sep 17 00:00:00 2001 From: Nicholas Vitovitch Date: Tue, 2 Feb 2016 00:41:20 +0100 Subject: [PATCH] Export transitive dependencies for static library --- CMakeLists.txt | 1 - docs/build.dox | 23 ++++++++++++++--------- examples/CMakeLists.txt | 2 -- src/CMakeLists.txt | 4 +++- tests/CMakeLists.txt | 2 -- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 507a9b40..244e51a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,7 +354,6 @@ endif() #-------------------------------------------------------------------- # Export GLFW library dependencies #-------------------------------------------------------------------- -set(GLFW_LIBRARIES ${glfw_LIBRARIES} CACHE STRING "Dependencies of GLFW") foreach(arg ${glfw_PKG_DEPS}) set(GLFW_PKG_DEPS "${GLFW_PKG_DEPS} ${arg}") endforeach() diff --git a/docs/build.dox b/docs/build.dox index d14cf799..32e19ade 100644 --- a/docs/build.dox +++ b/docs/build.dox @@ -158,6 +158,14 @@ will add the `glfw` target and the necessary cache variables to your project. add_subdirectory(path/to/glfw) @endcode +Once GLFW has been added to the project, link against it with the `glfw` target. +This adds all link-time dependencies of GLFW as it is currently configured and, +when applicable, the [GLFW_DLL](@ref build_macros) macro. + +@code{.cmake} +target_link_libraries(myapp glfw) +@endcode + To be able to include the GLFW header from your code, you need to tell the compiler where to find it. @@ -165,21 +173,18 @@ 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. +Note that it does not include GLU, as GLFW does not use it. If your application +needs GLU, you can find it by requiring the OpenGL package. @code{.cmake} -target_link_libraries(myapp glfw ${GLFW_LIBRARIES}) +find_package(OpenGL REQUIRED) @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. +Once found, the GLU library path is stored in the `OPENGL_glu_LIBRARY` cache +variable. @code{.cmake} -target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY} ${GLFW_LIBRARIES}) +target_link_libraries(myapp glfw ${OPENGL_glu_LIBRARY}) @endcode diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7b40ecb9..3f3f8983 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -3,8 +3,6 @@ link_libraries(glfw) if (BUILD_SHARED_LIBS) link_libraries("${MATH_LIBRARY}") -else() - link_libraries(${glfw_LIBRARIES}) endif() if (MSVC) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7c7dd973..2660dcac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,7 +100,9 @@ if (BUILD_SHARED_LIBS) endif() target_compile_definitions(glfw INTERFACE -DGLFW_DLL) - target_link_libraries(glfw ${glfw_LIBRARIES}) + target_link_libraries(glfw PRIVATE ${glfw_LIBRARIES}) +else() + target_link_libraries(glfw INTERFACE ${glfw_LIBRARIES}) endif() if (MSVC) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f1bce371..afa140fa 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -3,8 +3,6 @@ link_libraries(glfw) if (BUILD_SHARED_LIBS) link_libraries("${MATH_LIBRARY}") -else() - link_libraries(${glfw_LIBRARIES}) endif() if (MSVC)