Skip to content

Commit

Permalink
Create cmake imported targets for header-only modules too (#3495)
Browse files Browse the repository at this point in the history
* Modified PCLConfig.cmake.in so that header-only modules also generate imported targets

* Cmake fix to allow PCL targets import and link from build dir too.
  • Loading branch information
aslze authored and SergioRAgostinho committed Dec 2, 2019
1 parent 3e04ea7 commit 2e6fdd1
Showing 1 changed file with 44 additions and 39 deletions.
83 changes: 44 additions & 39 deletions PCLConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -405,29 +405,31 @@ endif()
if(EXISTS "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}/pcl/pcl_config.h")
# Found a PCL installation
# pcl_message("Found a PCL installation")
set(PCL_INCLUDE_DIRS "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}")
set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include/pcl-${PCL_VERSION_MAJOR}.${PCL_VERSION_MINOR}")
set(PCL_LIBRARY_DIRS "${PCL_ROOT}/@LIB_INSTALL_DIR@")
if(EXISTS "${PCL_ROOT}/3rdParty")
set(PCL_ALL_IN_ONE_INSTALLER ON)
endif()
elseif(EXISTS "${PCL_ROOT}/include/pcl/pcl_config.h")
# Found a non-standard (likely ANDROID) PCL installation
# pcl_message("Found a PCL installation")
set(PCL_INCLUDE_DIRS "${PCL_ROOT}/include")
set(PCL_CONF_INCLUDE_DIR "${PCL_ROOT}/include")
set(PCL_LIBRARY_DIRS "${PCL_ROOT}/lib")
if(EXISTS "${PCL_ROOT}/3rdParty")
set(PCL_ALL_IN_ONE_INSTALLER ON)
endif()
elseif(EXISTS "${PCL_DIR}/include/pcl/pcl_config.h")
# Found PCLConfig.cmake in a build tree of PCL
# pcl_message("PCL found into a build tree.")
set(PCL_INCLUDE_DIRS "${PCL_DIR}/include") # for pcl_config.h
set(PCL_CONF_INCLUDE_DIR "${PCL_DIR}/include") # for pcl_config.h
set(PCL_LIBRARY_DIRS "${PCL_DIR}/@LIB_INSTALL_DIR@")
set(PCL_SOURCES_TREE "@CMAKE_SOURCE_DIR@")
else()
pcl_report_not_found("PCL can not be found on this machine")
endif()

set(PCL_INCLUDE_DIRS "${PCL_CONF_INCLUDE_DIR}")

#set a suffix for debug libraries
set(PCL_DEBUG_SUFFIX "@CMAKE_DEBUG_POSTFIX@")
set(PCL_RELEASE_SUFFIX "@CMAKE_RELEASE_POSTFIX@")
Expand Down Expand Up @@ -614,43 +616,46 @@ foreach(component ${PCL_TO_FIND_COMPONENTS})
IMPORTED_IMPLIB "${PCL_${COMPONENT}_LIBRARY}"
)
endif()
foreach(def ${PCL_DEFINITIONS})
string(REPLACE " " ";" def2 ${def})
string(REGEX REPLACE "^-D" "" def3 "${def2}")
list(APPEND definitions ${def3})
endforeach()
if(CMAKE_VERSION VERSION_LESS 3.3)
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "${PCL_COMPILE_OPTIONS}"
INTERFACE_COMPILE_FEATURES "@PCL_CXX_COMPILE_FEATURES@"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}"
)
elseif(CMAKE_VERSION VERSION_LESS 3.11)
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
INTERFACE_COMPILE_FEATURES "@PCL_CXX_COMPILE_FEATURES@"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}"
)
else()
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS}"
)
# If possible, we use target_link_libraries to avoid problems with link-type keywords,
# see https://github.com/PointCloudLibrary/pcl/issues/2989
# target_link_libraries on imported libraries is supported only since CMake 3.11
target_link_libraries(${pcl_component} INTERFACE ${PCL_${COMPONENT}_LINK_LIBRARIES})
endif()
set(PCL_${COMPONENT}_LIBRARIES ${pcl_component})
else() # header-only
add_library(${pcl_component} INTERFACE IMPORTED)
endif()

foreach(def ${PCL_DEFINITIONS})
string(REPLACE " " ";" def2 ${def})
string(REGEX REPLACE "^-D" "" def3 "${def2}")
list(APPEND definitions ${def3})
endforeach()
if(CMAKE_VERSION VERSION_LESS 3.3)
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "${PCL_COMPILE_OPTIONS}"
INTERFACE_COMPILE_FEATURES "@PCL_CXX_COMPILE_FEATURES@"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS};${PCL_CONF_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}"
)
elseif(CMAKE_VERSION VERSION_LESS 3.11)
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
INTERFACE_COMPILE_FEATURES "@PCL_CXX_COMPILE_FEATURES@"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS};${PCL_CONF_INCLUDE_DIR}"
INTERFACE_LINK_LIBRARIES "${PCL_${COMPONENT}_LINK_LIBRARIES}"
)
else()
set_target_properties(${pcl_component}
PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${definitions}"
INTERFACE_COMPILE_OPTIONS "$<$<COMPILE_LANGUAGE:CXX>:${PCL_COMPILE_OPTIONS}>"
INTERFACE_INCLUDE_DIRECTORIES "${PCL_${COMPONENT}_INCLUDE_DIRS};${PCL_CONF_INCLUDE_DIR}"
)
# If possible, we use target_link_libraries to avoid problems with link-type keywords,
# see https://github.com/PointCloudLibrary/pcl/issues/2989
# target_link_libraries on imported libraries is supported only since CMake 3.11
target_link_libraries(${pcl_component} INTERFACE ${PCL_${COMPONENT}_LINK_LIBRARIES})
endif()
set(PCL_${COMPONENT}_LIBRARIES ${pcl_component})
endif()
endforeach()

Expand Down

0 comments on commit 2e6fdd1

Please sign in to comment.