Skip to content

Commit

Permalink
rewrite exported include dirs when pointing to absolute source / buil…
Browse files Browse the repository at this point in the history
…d / devel space (#600)
  • Loading branch information
dirk-thomas committed Mar 3, 2014
1 parent cb89563 commit b70f5a6
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmake/all.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ foreach(filename
parse_arguments
safe_execute_process
stamp
string_starts_with
platform/lsb
platform/ubuntu
platform/windows
Expand Down
18 changes: 10 additions & 8 deletions cmake/catkin_package.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -391,15 +391,17 @@ function(_catkin_package)
set(PROJECT_CMAKE_CONFIG_INCLUDE_DIRS "")
set(PROJECT_PKG_CONFIG_INCLUDE_DIRS "")
foreach(idir ${PROJECT_INCLUDE_DIRS})
# include folders in devel space are handled like relative ones
# include dirs in source / build / devel space are handled like relative ones
# since these files are supposed to be installed to the include folder in install space
string(LENGTH "${CATKIN_DEVEL_PREFIX}/" devel_length)
string(LENGTH "${idir}/" idir_length)
if(NOT ${idir_length} LESS ${devel_length})
string(SUBSTRING "${idir}/" 0 ${devel_length} idir_prefix)
if("${idir_prefix}" STREQUAL "${CATKIN_DEVEL_PREFIX}/")
# the value doesn't matter as long as it doesn't match IS_ABSOLUTE
set(idir "${CATKIN_GLOBAL_INCLUDE_DESTINATION}")
string_starts_with("${idir}/" "${CMAKE_CURRENT_SOURCE_DIR}/" _is_source_prefix)
string_starts_with("${idir}/" "${CMAKE_CURRENT_BINARY_DIR}/" _is_build_prefix)
string_starts_with("${idir}/" "${CATKIN_DEVEL_PREFIX}/" _is_devel_prefix)
if(_is_source_prefix OR _is_build_prefix OR _is_devel_prefix)
# the value doesn't matter as long as it doesn't match IS_ABSOLUTE
set(idir "${CATKIN_GLOBAL_INCLUDE_DESTINATION}")
# generated header files should be places in the devel space rather then in the build space
if(_is_build_prefix)
message(WARNING "catkin_package() include dir '${idir}' should be placed in the devel space instead of the build space")
endif()
endif()
if(IS_ABSOLUTE ${idir})
Expand Down
22 changes: 22 additions & 0 deletions cmake/string_starts_with.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#
# Check if a string starts with a prefix.
#
# :param str: the string
# :type str: string
# :param prefix: the prefix
# :type prefix: string
# :param var: the output variable name
# :type var: bool
#
function(string_starts_with str prefix var)
string(LENGTH "${str}" str_length)
string(LENGTH "${prefix}" prefix_length)
set(value FALSE)
if(NOT ${str_length} LESS ${prefix_length})
string(SUBSTRING "${str}" 0 ${prefix_length} str_prefix)
if("${str_prefix}" STREQUAL "${prefix}")
set(value TRUE)
endif()
endif()
set(${var} ${value} PARENT_SCOPE)
endfunction()

0 comments on commit b70f5a6

Please sign in to comment.