Skip to content

Commit 57ee8c4

Browse files
committed
cmake: Improve find_library and link usage
According to CMake docs, "link_directories() is rarely necessary". Therefore remove link_directories(), and use find_library() after pkg_check_modules() to obtain full paths of libraries. Because of policy change of CMP0063, only set visibility properties for freenect2. Do not make them global.
1 parent 0ce650f commit 57ee8c4

File tree

4 files changed

+20
-14
lines changed

4 files changed

+20
-14
lines changed

CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ INCLUDE_DIRECTORIES(
6565
${TurboJPEG_INCLUDE_DIRS}
6666
)
6767

68-
LINK_DIRECTORIES(${LibUSB_LIBRARY_DIRS})
69-
7068
SET(RESOURCES_INC_FILE "${PROJECT_BINARY_DIR}/resources.inc.h")
7169

7270
SET(SOURCES
@@ -132,7 +130,6 @@ IF(ENABLE_OPENGL)
132130
IF(GLFW3_FOUND)
133131
INCLUDE_DIRECTORIES(${GLFW3_INCLUDE_DIRS})
134132

135-
LINK_DIRECTORIES(${GLFW3_LIBRARY_DIRS})
136133
LIST(APPEND LIBRARIES
137134
${GLFW3_LIBRARIES}
138135
${OPENGL_gl_LIBRARY}
@@ -204,12 +201,12 @@ CONFIGURE_FILE("${MY_DIR}/include/libfreenect2/config.h.in" "${PROJECT_BINARY_DI
204201
GENERATE_RESOURCES(${RESOURCES_INC_FILE} ${MY_DIR} ${RESOURCES})
205202

206203
ADD_DEFINITIONS(-DRESOURCES_INC)
207-
SET(CMAKE_CXX_VISIBILITY_PRESET hidden)
208-
SET(CMAKE_C_VISIBILITY_PRESET hidden)
209-
SET(CMAKE_VISIBILITY_INLINES_HIDDEN 1)
210-
INCLUDE(GenerateExportHeader)
211-
212204
ADD_LIBRARY(freenect2 ${SOURCES})
205+
SET_TARGET_PROPERTIES(freenect2 PROPERTIES
206+
CXX_VISIBILITY_PRESET hidden
207+
VISIBILITY_INLINES_HIDDEN 1
208+
)
209+
INCLUDE(GenerateExportHeader)
213210
GENERATE_EXPORT_HEADER(freenect2
214211
BASE_NAME libfreenect2
215212
EXPORT_FILE_NAME libfreenect2/export.h
@@ -219,7 +216,8 @@ IF(MSVC AND NOT BUILD_SHARED_LIBS)
219216
# MSVC creates freenect2.lib for both dynamic and static by default
220217
set_target_properties(freenect2 PROPERTIES SUFFIX "static.lib")
221218
ENDIF()
222-
MESSAGE(STATUS "Linking with these libraries: ${LIBRARIES}")
219+
STRING(REPLACE ";" "\n " LIBRARIES_STRING "${LIBRARIES}")
220+
MESSAGE(STATUS "Linking with these libraries: \n ${LIBRARIES_STRING}")
223221
TARGET_LINK_LIBRARIES(freenect2 ${LIBRARIES})
224222

225223
CONFIGURE_FILE(freenect2.cmake.in "${PROJECT_BINARY_DIR}/freenect2Config.cmake" @ONLY)

cmake_modules/FindGLFW3.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ IF(PKG_CONFIG_FOUND)
1414
SET(ENV{PKG_CONFIG_PATH} "${DEPENDS_DIR}/glfw/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}")
1515
PKG_CHECK_MODULES(GLFW3 glfw3)
1616

17+
FIND_LIBRARY(GLFW3_LIBRARY
18+
NAMES ${GLFW3_LIBRARIES}
19+
HINTS ${GLFW3_LIBRARY_DIRS}
20+
)
21+
SET(GLFW3_LIBRARIES ${GLFW3_LIBRARY})
22+
1723
RETURN()
1824
ENDIF()
1925

cmake_modules/FindLibUSB.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ IF(PKG_CONFIG_FOUND)
1616
ELSE()
1717
PKG_CHECK_MODULES(LibUSB libusb-1.0)
1818
ENDIF()
19+
20+
FIND_LIBRARY(LibUSB_LIBRARY
21+
NAMES ${LibUSB_LIBRARIES}
22+
HINTS ${LibUSB_LIBRARY_DIRS}
23+
)
24+
SET(LibUSB_LIBRARIES ${LibUSB_LIBRARY})
25+
1926
RETURN()
2027
ENDIF()
2128

examples/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ INCLUDE_DIRECTORIES(
3737
${freenect2_INCLUDE_DIR}
3838
)
3939

40-
LINK_DIRECTORIES(
41-
${freenect2_LIBRARY_DIRS}
42-
)
43-
4440
SET(Protonect_src
4541
Protonect.cpp
4642
)
@@ -58,7 +54,6 @@ IF(ENABLE_OPENGL)
5854
${flextGL_INCLUDE_DIRS}
5955
)
6056

61-
LINK_DIRECTORIES(${GLFW3_LIBRARY_DIRS})
6257
LIST(APPEND Protonect_src
6358
viewer.cpp
6459
${flextGL_SOURCES}

0 commit comments

Comments
 (0)