Skip to content

Commit 6f5d1ac

Browse files
authored
Modernize CMake scripts and update QGLViewer to 2.9.1 (#439)
This is a rewrite of the CMake configuration that removes a lot of legacy code which is no longer needed and makes the build system more convoluted than necessary. By switching to modern CMake semantics, we gain the following advantages: * Include directories and dependent libraries are associated with the exported target, no additional configuration beyond target_link_libraries() required. * Built-in Qt MOC and UIC handling * Proper separation of build and install interface; this also makes RPATH just work out of the box without additional configuration. * Native build of vendored QGLViewer library, no need to call qmake and import the result. * Proper handling and versioning of dependencies. No hard-coded build paths showing up in unexpected places. Additional changes: * Update vendored copy of QGLViewer to version 2.9.1 * Prefer system install of QGLViewer * Auto-detect matchin Qt Version 5 or 6 (switchable) Signed-off-by: Timo Röhling <[email protected]> This is needed for Qt6 support. Signed-off-by: Timo Röhling <[email protected]> * Try harder to pick matching Qt and QGLViewer libraries Signed-off-by: Timo Röhling <[email protected]> * Add option to make octovis build optional Signed-off-by: Timo Röhling <[email protected]> * Fix increase_version.py to deal with new CMakeLists.txt files Signed-off-by: Timo Röhling <[email protected]> * Add missing return() Signed-off-by: Timo Röhling <[email protected]> --------- Signed-off-by: Timo Röhling <[email protected]>
1 parent 56053a4 commit 6f5d1ac

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+13471
-12985
lines changed

CMakeLists.txt

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
2-
PROJECT( octomap-distribution )
1+
cmake_minimum_required(VERSION 3.10...4.1)
2+
project(
3+
octomap-distribution
4+
VERSION 1.10.0
5+
LANGUAGES NONE
6+
)
37

4-
ENABLE_TESTING() # enable CTest environment of subprojects
5-
set(CMAKE_POSITION_INDEPENDENT_CODE ON) # enables -fPIC in applicable compilers (required to avoid link errors in some cases)
8+
include(CTest)
69

10+
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
711
option(BUILD_OCTOVIS_SUBPROJECT "Build targets from subproject octovis" ON)
8-
option(BUILD_DYNAMICETD3D_SUBPROJECT "Build targets from subproject dynamicEDT3D" ON)
9-
option(OCTOVIS_QT6 "Link Octovis against Qt6?" ON)
10-
11-
set(CMAKE_CXX_STANDARD 11)
12-
13-
ADD_SUBDIRECTORY( octomap )
12+
option(BUILD_DYNAMICETD3D_SUBPROJECT
13+
"Build targets from subproject dynamicEDT3D" ON
14+
)
1415

16+
add_subdirectory(octomap)
1517
if(BUILD_OCTOVIS_SUBPROJECT)
16-
ADD_SUBDIRECTORY( octovis )
18+
set(OCTOVIS_BUILD_OPTIONAL TRUE)
19+
add_subdirectory(octovis)
1720
endif()
18-
1921
if(BUILD_DYNAMICETD3D_SUBPROJECT)
20-
ADD_SUBDIRECTORY( dynamicEDT3D )
22+
add_subdirectory(dynamicEDT3D)
2123
endif()

dynamicEDT3D/CMakeLists.txt

Lines changed: 115 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -1,177 +1,139 @@
1-
CMAKE_MINIMUM_REQUIRED(VERSION 3.10)
2-
PROJECT(dynamicEDT3D)
3-
4-
include(CTest)
5-
include(GNUInstallDirs)
1+
cmake_minimum_required(VERSION 3.10...4.1)
2+
project(
3+
dynamicEDT3D
4+
VERSION 1.10.0
5+
LANGUAGES CXX
6+
)
67

7-
# version (e.g. for packaging)
8-
set(DYNAMICEDT3D_MAJOR_VERSION 1)
9-
set(DYNAMICEDT3D_MINOR_VERSION 10)
10-
set(DYNAMICEDT3D_PATCH_VERSION 0)
11-
set(DYNAMICEDT3D_VERSION ${DYNAMICEDT3D_MAJOR_VERSION}.${DYNAMICEDT3D_MINOR_VERSION}.${DYNAMICEDT3D_PATCH_VERSION})
12-
set(DYNAMICEDT3D_SOVERSION ${DYNAMICEDT3D_MAJOR_VERSION}.${DYNAMICEDT3D_MINOR_VERSION})
13-
14-
if(COMMAND cmake_policy)
15-
cmake_policy(SET CMP0003 NEW)
16-
if(POLICY CMP0042)
17-
# Enable MACOSX_RPATH by default.
18-
cmake_policy(SET CMP0042 NEW)
19-
endif(POLICY CMP0042)
20-
endif(COMMAND cmake_policy)
21-
22-
SET (CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules")
23-
24-
# COMPILER SETTINGS (default: Release) and flags
25-
INCLUDE(CompilerSettings)
26-
27-
28-
# Set output directories for libraries and executables
29-
SET( BASE_DIR ${CMAKE_SOURCE_DIR} )
30-
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY ${BASE_DIR}/lib )
31-
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${BASE_DIR}/lib )
32-
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BASE_DIR}/bin )
33-
# output dirs for multi-config builds (MSVC)
34-
foreach( OUTPUTCONFIG ${CMAKE_CONFIGURATION_TYPES} )
35-
STRING( TOUPPER ${OUTPUTCONFIG} OUTPUTCONFIG )
36-
SET( CMAKE_LIBRARY_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${BASE_DIR}/lib )
37-
SET( CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${BASE_DIR}/lib )
38-
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY_${OUTPUTCONFIG} ${BASE_DIR}/bin )
39-
endforeach( OUTPUTCONFIG CMAKE_CONFIGURATION_TYPES )
40-
41-
set(INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include")
42-
INCLUDE_DIRECTORIES(${INCLUDE_DIRS})
43-
44-
LINK_DIRECTORIES(${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
8+
option(DYNAMICEDT3D_BUILD_EXAMPLES "Build examples" ON)
459

46-
# Installation
10+
include(CMakePackageConfigHelpers)
11+
include(GNUInstallDirs)
4712

48-
set(INSTALL_TARGETS_DEFAULT_ARGS
49-
RUNTIME DESTINATION bin
50-
LIBRARY DESTINATION lib
51-
ARCHIVE DESTINATION lib
52-
)
13+
set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules")
14+
include(CompilerSettings)
15+
include(InstallPkgConfigFile)
5316

54-
find_package(octomap REQUIRED
55-
HINTS ${CMAKE_SOURCE_DIR}/lib/cmake/octomap
56-
${CMAKE_SOURCE_DIR}/../octomap/lib/cmake/octomap
17+
# version (e.g. for packaging)
18+
set(DYNAMICEDT3D_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
19+
set(DYNAMICEDT3D_MINOR_VERSION ${PROJECT_VERSION_MINOR})
20+
set(DYNAMICEDT3D_PATCH_VERSION ${PROJECT_VERSION_PATCH})
21+
set(DYNAMICEDT3D_VERSION ${PROJECT_VERSION})
22+
set(DYNAMICEDT3D_SOVERSION
23+
"${DYNAMICEDT3D_MAJOR_VERSION}.${DYNAMICEDT3D_MINOR_VERSION}"
5724
)
58-
MESSAGE(STATUS "Found octomap version: " ${octomap_VERSION})
59-
MESSAGE(STATUS "octomap libraries: ${OCTOMAP_LIBRARIES}")
60-
61-
INCLUDE_DIRECTORIES(BEFORE SYSTEM ${OCTOMAP_INCLUDE_DIRS})
6225

63-
ADD_SUBDIRECTORY(src)
26+
if(NOT TARGET octomap::octomap)
27+
find_package(octomap "${DYNAMICEDT3D_VERSION}" REQUIRED)
28+
endif()
6429

30+
set(DYNAMICEDT3D_FIND_DEPENDENCIES
31+
"include(CMakeFindDependencyMacro)\nfind_dependency(octomap ${DYNAMICEDT3D_VERSION})"
32+
)
6533

66-
file(GLOB dynamicEDT3D_HDRS ${PROJECT_SOURCE_DIR}/include/dynamicEDT3D/*.h ${PROJECT_SOURCE_DIR}/include/dynamicEDT3D/*.hxx)
67-
install(FILES ${dynamicEDT3D_HDRS} DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/dynamicEDT3D")
34+
set(dynamicEDT3D_SOURCES src/dynamicEDT3D.cpp)
6835

69-
# Install catkin package.xml, attention package.xml names the catkin package "dynamic_edt_3d", so this is also the location where it needs to be installed to (and not "dynamicEDT3D")
70-
install(FILES package.xml DESTINATION "${CMAKE_INSTALL_DATADIR}/dynamic_edt_3d")
36+
add_library(dynamicEDT3D ${dynamicEDT3D_SOURCES})
37+
target_compile_features(dynamicEDT3D PUBLIC cxx_std_11)
38+
target_include_directories(
39+
dynamicEDT3D PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
40+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
41+
)
42+
set_target_properties(
43+
dynamicEDT3D
44+
PROPERTIES VERSION "${DYNAMICEDT3D_VERSION}"
45+
SOVERSION "${DYNAMICEDT3D_SOVERSION}"
46+
OUTPUT_NAME "dynamicedt3d"
47+
)
48+
target_link_libraries(dynamicEDT3D PUBLIC octomap::octomap)
49+
add_library(octomap::dynamicEDT3D ALIAS dynamicEDT3D)
7150

72-
# Allows Colcon to find non-Ament packages when using workspace underlays
73-
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/share/ament_index/resource_index/packages/${PROJECT_NAME} "")
74-
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/ament_index/resource_index/packages/${PROJECT_NAME} DESTINATION share/ament_index/resource_index/packages)
51+
# Examples
52+
if(DYNAMICEDT3D_BUILD_EXAMPLES)
53+
add_executable(exampleEDT3D src/examples/exampleEDT3D.cpp)
54+
target_link_libraries(exampleEDT3D PRIVATE dynamicEDT3D)
7555

76-
#TODO: this conflicts with the octomap uninstall
77-
#it is not only a target name problem, also both will use the same manifest file
78-
#in the same binary directory
79-
if(NOT TARGET uninstall)
80-
configure_file(
81-
"${PROJECT_SOURCE_DIR}/CMakeModules/CMakeUninstall.cmake.in"
82-
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
83-
IMMEDIATE @ONLY)
56+
add_executable(exampleEDTOctomap src/examples/exampleEDTOctomap.cpp)
57+
target_link_libraries(exampleEDTOctomap PRIVATE dynamicEDT3D)
8458

85-
add_custom_target(uninstall
86-
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
59+
add_executable(
60+
exampleEDTOctomapStamped src/examples/exampleEDTOctomapStamped.cpp
61+
)
62+
target_link_libraries(exampleEDTOctomapStamped PRIVATE dynamicEDT3D)
8763
endif()
8864

89-
# Export the package for use from the build-tree
90-
# (this registers the build-tree with a global CMake-registry)
65+
# Export build tree
66+
configure_package_config_file(
67+
dynamicedt3d-config.cmake.in
68+
"${CMAKE_CURRENT_BINARY_DIR}/dynamicedt3d-config.cmake"
69+
INSTALL_DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
70+
)
71+
write_basic_package_version_file(
72+
"${CMAKE_CURRENT_BINARY_DIR}/dynamicedt3d-config-version.cmake"
73+
VERSION ${DYNAMICEDT3D_VERSION}
74+
COMPATIBILITY SameMinorVersion
75+
)
76+
export(
77+
TARGETS dynamicEDT3D
78+
NAMESPACE octomap::
79+
FILE "${CMAKE_CURRENT_BINARY_DIR}/dynamicedt3d-targets.cmake"
80+
)
9181
export(PACKAGE dynamicEDT3D)
9282

93-
# Create a dynamicEDT3DConfig.cmake file for the use from the build tree
94-
set(DYNAMICEDT3D_INCLUDE_DIRS "${INCLUDE_DIRS}")
95-
set(DYNAMICEDT3D_LIB_DIR "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
96-
# Set library names as absolute paths
97-
# Windows, spec. MSVC requires the .lib suffix for imported libs
98-
IF(WIN32)
99-
set(DYNAMICEDT3D_LIBRARY
100-
"${CMAKE_IMPORT_LIBRARY_PREFIX}dynamicedt3d${CMAKE_IMPORT_LIBRARY_SUFFIX}"
101-
)
102-
ELSE()
103-
set(DYNAMICEDT3D_LIBRARY
104-
"${CMAKE_SHARED_LIBRARY_PREFIX}dynamicedt3d${CMAKE_SHARED_LIBRARY_SUFFIX}"
105-
)
106-
ENDIF()
107-
# not used right now (export depends?)
108-
#set(DYNEDT3D_CMAKE_DIR "${PROJECT_BINARY_DIR}")
109-
include(CMakePackageConfigHelpers)
83+
# Installation
84+
install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
85+
install(TARGETS dynamicEDT3D EXPORT dynamicedt3d-targets)
86+
install(
87+
EXPORT dynamicedt3d-targets
88+
NAMESPACE octomap::
89+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynamicEDT3D"
90+
)
91+
set(DYNAMICEDT3D_INCLUDE_DIRS "${CMAKE_INSTALL_INCLUDEDIR}")
92+
set(DYNAMICEDT3D_LIBRARY_DIRS "${CMAKE_INSTALL_LIBDIR}")
93+
configure_package_config_file(
94+
dynamicedt3d-config.cmake.in
95+
"${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/dynamicedt3d-config.cmake"
96+
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynamicEDT3D"
97+
)
98+
write_basic_package_version_file(
99+
"${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/dynamicedt3d-config-version.cmake"
100+
VERSION ${DYNAMICEDT3D_VERSION}
101+
COMPATIBILITY SameMinorVersion
102+
)
103+
install(
104+
FILES
105+
"${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/dynamicedt3d-config.cmake"
106+
"${CMAKE_CURRENT_BINARY_DIR}/InstallFiles/dynamicedt3d-config-version.cmake"
107+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/dynamicEDT3D"
108+
)
110109

111-
CONFIGURE_PACKAGE_CONFIG_FILE(
112-
dynamicEDT3DConfig.cmake.in
113-
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/dynamicEDT3D/dynamicEDT3DConfig.cmake"
114-
PATH_VARS DYNAMICEDT3D_INCLUDE_DIRS DYNAMICEDT3D_LIB_DIR
115-
INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/dynamicEDT3D")
116-
117-
WRITE_BASIC_PACKAGE_VERSION_FILE(
118-
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/cmake/dynamicEDT3D/dynamicEDT3DConfig-version.cmake"
119-
VERSION ${DYNAMICEDT3D_VERSION}
120-
COMPATIBILITY AnyNewerVersion)
121-
122-
# Install the export set for use with the install-tree
123-
#install(EXPORT FooBarLibraryDepends DESTINATION
124-
# "${INSTALL_DATA_DIR}/FooBar/CMake"
125-
# COMPONENT dev)
126-
127-
# Create a dynamicEDT3DConfig.cmake file for the use from the install tree
128-
# and install it
129-
set(DYNAMICEDT3D_INCLUDE_DIRS "${CMAKE_INSTALL_FULL_INCLUDEDIR}")
130-
set(DYNAMICEDT3D_LIB_DIR "${CMAKE_INSTALL_FULL_LIBDIR}")
131-
#set(DYNAMICEDT3D_CMAKE_DIR "${INSTALL_DATA_DIR}/FooBar/CMake")
132-
133-
set(DYNAMICEDT3D_INCLUDE_TARGETS
134-
"include(\${CMAKE_CURRENT_LIST_DIR}/dynamicEDT3DTargets.cmake)")
135-
136-
CONFIGURE_PACKAGE_CONFIG_FILE(
137-
dynamicEDT3DConfig.cmake.in
138-
"${PROJECT_BINARY_DIR}/InstallFiles/dynamicEDT3DConfig.cmake"
139-
PATH_VARS DYNAMICEDT3D_INCLUDE_DIRS DYNAMICEDT3D_LIB_DIR
140-
INSTALL_DESTINATION "${CMAKE_INSTALL_FULL_DATADIR}/dynamicEDT3D")
141-
142-
WRITE_BASIC_PACKAGE_VERSION_FILE(
143-
"${PROJECT_BINARY_DIR}/InstallFiles/dynamicEDT3DConfig-version.cmake"
144-
VERSION ${DYNAMICEDT3D_VERSION}
145-
COMPATIBILITY AnyNewerVersion)
146-
147-
install(FILES
148-
"${PROJECT_BINARY_DIR}/InstallFiles/dynamicEDT3DConfig.cmake"
149-
"${PROJECT_BINARY_DIR}/InstallFiles/dynamicEDT3DConfig-version.cmake"
150-
DESTINATION "${CMAKE_INSTALL_DATADIR}/dynamicEDT3D")
151-
152-
# Write pkgconfig-file:
110+
# ROS support
111+
install(FILES package.xml DESTINATION "${CMAKE_INSTALL_DATADIR}/dynamicEDT3D")
112+
113+
# pkg-config support
153114
include(InstallPkgConfigFile)
154-
install_pkg_config_file(dynamicEDT3D
115+
install_pkg_config_file(
116+
dynamicEDT3D
155117
CFLAGS
156-
LIBS -ldynamicEDT3D
118+
LIBS
119+
-ldynamicedt3d
157120
REQUIRES
158-
VERSION ${DYNAMICEDT3D_VERSION})
159-
121+
octomap
122+
VERSION
123+
${DYNAMICEDT3D_VERSION}
124+
)
160125

161126
# Documentation
162-
FIND_PACKAGE(Doxygen)
163-
IF(DOXYGEN_FOUND)
164-
ADD_CUSTOM_TARGET(docs_dynamicEDT3D ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/dynamicEDT3D.dox
165-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
166-
COMMENT "Generating documentation (Doxygen)...")
167-
ENDIF(DOXYGEN_FOUND)
127+
find_package(Doxygen QUIET)
128+
if(DOXYGEN_FOUND)
129+
add_custom_target(
130+
docs_dynamicEDT3D
131+
COMMAND ${DOXYGEN_EXECUTABLE}
132+
${CMAKE_CURRENT_SOURCE_DIR}/dynamicEDT3D.dox
133+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
134+
COMMENT "Generating documentation (Doxygen)"
135+
)
136+
endif(DOXYGEN_FOUND)
168137

169138
# Needs to be last statement:
170-
INCLUDE(CPackSettings)
171-
172-
# Finished:
173-
MESSAGE (STATUS "\n")
174-
MESSAGE (STATUS "Compile dynamicEDT3D using: make")
175-
MESSAGE (STATUS "Install dynamicEDT3D using: make install")
176-
MESSAGE (STATUS " (be sure to set the correct CMAKE_INSTALL_PREFIX before)")
177-
MESSAGE (STATUS "Compile API-documentation using: make docs_dynamicEDT3D\n")
139+
include(CPackSettings)

dynamicEDT3D/CMakeModules/CMakeUninstall.cmake.in

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)