Skip to content

Commit 0509537

Browse files
committed
determine the location of the stage library using a generator expression
also makes it relocatable in the process fix stage cmake config and make it relocatable fix stage config file (even for saucy)
1 parent 83555f3 commit 0509537

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

CMakeLists.txt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,6 @@ ENDFOREACH(INC ${PC_INCLUDE_DIRS})
137137
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/stage.pc.in ${CMAKE_CURRENT_BINARY_DIR}/stage.pc @ONLY)
138138
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/stage.pc DESTINATION ${PROJECT_LIB_DIR}/pkgconfig/)
139139

140-
# Create the CMake module files
141-
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/stage-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake @ONLY)
142-
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/stage-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/stage-config-version.cmake @ONLY)
143-
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/stage-config-version.cmake DESTINATION ${PROJECT_LIB_DIR}/cmake/${PROJECT_NAME})
144-
145140
# Install catkin package.xml
146141
install(FILES package.xml DESTINATION share/stage)
147142

@@ -182,6 +177,25 @@ IF ( BUILD_PLAYER_PLUGIN )
182177
ENDIF ( PLAYER_FOUND )
183178
ENDIF ( BUILD_PLAYER_PLUGIN )
184179

180+
# Create the CMake module files (needs to be run after the stage target was created)
181+
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.8.11)
182+
# Use a generator expression if the version of cmake allows it.
183+
set(STAGE_TARGET_NAME "$<TARGET_FILE_NAME:stage>")
184+
else()
185+
# Otherwise use the LOCATION property of the target (this will produce a warning on newer versions of cmake)
186+
get_property(location_ TARGET stage PROPERTY LOCATION)
187+
get_filename_component(STAGE_TARGET_NAME "${location_}" NAME)
188+
unset(location_)
189+
endif()
190+
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/stage-config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake @ONLY)
191+
if (${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION} GREATER 2.8.11)
192+
# Also run it through file(GENERATE ...) to expand generator expressions (if the version of cmake supports it).
193+
FILE (GENERATE
194+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake
195+
INPUT ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake)
196+
endif()
197+
CONFIGURE_FILE (${CMAKE_CURRENT_SOURCE_DIR}/stage-config-version.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/stage-config-version.cmake @ONLY)
198+
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/stage-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/stage-config-version.cmake DESTINATION ${PROJECT_LIB_DIR}/cmake/${PROJECT_NAME})
185199

186200
# generate a cpack config file used to create packaged tarballs
187201
IF ( CPACK_CFG )

stage-config.cmake.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set(STAGE_INCLUDE_DIRS "@CMAKE_INSTALL_PREFIX@/include/@PROJECT_NAME@-@APIVERSIO
88
"@OPENGL_INCLUDE_DIR@")
99
list(REMOVE_DUPLICATES STAGE_INCLUDE_DIRS)
1010
set(STAGE_LIBRARIES
11-
"@CMAKE_INSTALL_PREFIX@/@PROJECT_LIB_DIR@/libstage.so"
11+
"${stage_DIR}/../../../@PROJECT_LIB_DIR@/@STAGE_TARGET_NAME@"
1212
"@FLTK_LIBRARIES@"
1313
"@OPENGL_gl_LIBRARIES@")
1414

0 commit comments

Comments
 (0)