From 837116a068341b9889215dcd2fe63b15a9db99ab Mon Sep 17 00:00:00 2001 From: Armin Hornung Date: Tue, 26 Jul 2011 16:06:36 +0000 Subject: [PATCH] more CMake tweaks: uninstall target, build static and dynamic libs --- CMakeLists.txt | 18 +++++++++++++++++- CMakeModules/CMakeUninstall.cmake.in | 22 ++++++++++++++++++++++ CMakeModules/CPackSettings.cmake | 10 ++-------- include/octomap/OccupancyOcTreeBase.h | 2 +- include/octomap/OccupancyOcTreeBase.hxx | 9 ++++----- src/octomap/CMakeLists.txt | 11 +++++++++-- src/octomap/math/CMakeLists.txt | 12 +++++------- src/octovis/CMakeLists.txt | 17 ++++++++++++----- 8 files changed, 72 insertions(+), 29 deletions(-) create mode 100644 CMakeModules/CMakeUninstall.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index e35b039e..00bb66b9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -61,6 +61,16 @@ install(FILES ${octomap_HDRS} DESTINATION include/octomap) file(GLOB octomap_math_HDRS ${CMAKE_SOURCE_DIR}/include/octomap/math/*.h) install(FILES ${octomap_math_HDRS} DESTINATION include/octomap/math) +# uninstall target +configure_file( + "CMakeModules/CMakeUninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + + # Export the package for use from the build-tree # (this registers the build-tree with a global CMake-registry) export(PACKAGE octomap) @@ -94,7 +104,13 @@ install(FILES "${PROJECT_BINARY_DIR}/InstallFiles/octomap-config-version.cmake" DESTINATION lib/cmake/octomap/) - +# Write pkgconfig-file: +include(CMakeModules/InstallPkgConfigFile.cmake) +install_pkg_config_file(octomap + CFLAGS + LIBS -loctomap -loctomath + REQUIRES + VERSION ${OCTOMAP_MAJOR_VERSION}.${OCTOMAP_MINOR_VERSION}.${OCTOMAP_PATCH_VERSION}) # Documentation FIND_PACKAGE(Doxygen) diff --git a/CMakeModules/CMakeUninstall.cmake.in b/CMakeModules/CMakeUninstall.cmake.in new file mode 100644 index 00000000..c6d80941 --- /dev/null +++ b/CMakeModules/CMakeUninstall.cmake.in @@ -0,0 +1,22 @@ +if (NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + message(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +endif(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +file(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +string(REGEX REPLACE "\n" ";" files "${files}") +list(REVERSE files) +foreach (file ${files}) + message(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + if (EXISTS "$ENV{DESTDIR}${file}") + execute_process( + COMMAND @CMAKE_COMMAND@ -E remove "$ENV{DESTDIR}${file}" + OUTPUT_VARIABLE rm_out + RESULT_VARIABLE rm_retval + ) + if(NOT ${rm_retval} EQUAL 0) + message(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + endif (NOT ${rm_retval} EQUAL 0) + else (EXISTS "$ENV{DESTDIR}${file}") + message(STATUS "File \"$ENV{DESTDIR}${file}\" does not exist.") + endif (EXISTS "$ENV{DESTDIR}${file}") +endforeach(file) diff --git a/CMakeModules/CPackSettings.cmake b/CMakeModules/CPackSettings.cmake index 88871991..d716762b 100644 --- a/CMakeModules/CPackSettings.cmake +++ b/CMakeModules/CPackSettings.cmake @@ -8,14 +8,8 @@ SET(CPACK_PACKAGE_CONTACT "K.M. Wurm and A. Hornung") SET(CPACK_PACKAGE_VENDOR "University of Freiburg") SET(CPACK_GENERATOR "DEB") SET(CPACK_SOURCE_GENERATOR "TGZ") - - -include(CMakeModules/InstallPkgConfigFile.cmake) -install_pkg_config_file(octomap - CFLAGS - LIBS -loctomap -loctomath - REQUIRES - VERSION ${OCTOMAP_MAJOR_VERSION}.${OCTOMAP_MINOR_VERSION}.${OCTOMAP_PATCH_VERSION}) +SET(CPACK_SOURCE_PACKAGE_FILE_NAME + "${PROJECT_NAME}-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") # This must always be last statement! INCLUDE(CPack) diff --git a/include/octomap/OccupancyOcTreeBase.h b/include/octomap/OccupancyOcTreeBase.h index 76e081c9..5b6d2157 100644 --- a/include/octomap/OccupancyOcTreeBase.h +++ b/include/octomap/OccupancyOcTreeBase.h @@ -430,7 +430,7 @@ namespace octomap { protected: - + bool use_change_detection; bool use_bbx_limit; ///< use bounding box for queries (needs to be set)? point3d bbx_min; point3d bbx_max; diff --git a/include/octomap/OccupancyOcTreeBase.hxx b/include/octomap/OccupancyOcTreeBase.hxx index f46a2e77..ccf3a165 100644 --- a/include/octomap/OccupancyOcTreeBase.hxx +++ b/include/octomap/OccupancyOcTreeBase.hxx @@ -136,7 +136,7 @@ namespace octomap { void OccupancyOcTreeBase::computeUpdate(const Pointcloud& scan, const octomap::point3d& origin, KeySet& free_cells, KeySet& occupied_cells, - double maxrange) { + double maxrange){ for (Pointcloud::const_iterator point_it = scan.begin(); point_it != scan.end(); point_it++) { const point3d& p = *point_it; @@ -223,10 +223,9 @@ namespace octomap { NODE* OccupancyOcTreeBase::updateNode(const OcTreeKey& key, bool occupied, bool dirty) { NODE* leaf = this->search(key); - if (leaf) { - if ((isNodeAtThreshold(leaf)) && (isNodeOccupied(leaf) == occupied)) { - return leaf; - } + // no change: node already at threshold + if (leaf && (isNodeAtThreshold(leaf)) && (isNodeOccupied(leaf) == occupied)) { + return leaf; } return updateNodeRecurs(this->itsRoot, false, key, 0, occupied, dirty); } diff --git a/src/octomap/CMakeLists.txt b/src/octomap/CMakeLists.txt index 9ce6638a..1c37bfb1 100644 --- a/src/octomap/CMakeLists.txt +++ b/src/octomap/CMakeLists.txt @@ -9,7 +9,12 @@ SET (octomap_SRCS OcTreeLUT.cpp ) -ADD_LIBRARY( octomap ${octomap_SRCS}) +# dynamic and static libs, see CMake FAQ: +ADD_LIBRARY( octomap SHARED ${octomap_SRCS}) +ADD_LIBRARY( octomap-static STATIC ${octomap_SRCS}) +SET_TARGET_PROPERTIES(octomap-static PROPERTIES OUTPUT_NAME "octomap") +SET_TARGET_PROPERTIES(octomap-static PROPERTIES PREFIX "lib") + # Link in ROS libs e.g. for logging output if needed: if(WITH_ROS) @@ -54,7 +59,9 @@ TARGET_LINK_LIBRARIES(test_lut octomap) # file(GLOB octomap_impl_HDRS *.h *.hxx *.hpp) # install(FILES ${octomap_impl_HDRS} DESTINATION include/octomap) -install(TARGETS octomap +install(TARGETS + octomap + octomap-static graph2tree log2graph binvox2bt diff --git a/src/octomap/math/CMakeLists.txt b/src/octomap/math/CMakeLists.txt index c2d04c38..6be1801b 100644 --- a/src/octomap/math/CMakeLists.txt +++ b/src/octomap/math/CMakeLists.txt @@ -5,11 +5,9 @@ SET (octomath_SRCS ) -ADD_LIBRARY( octomath ${octomath_SRCS}) +ADD_LIBRARY( octomath SHARED ${octomath_SRCS}) +ADD_LIBRARY( octomath-static STATIC ${octomath_SRCS}) +SET_TARGET_PROPERTIES(octomath-static PROPERTIES OUTPUT_NAME "octomath") +SET_TARGET_PROPERTIES(octomath-static PROPERTIES PREFIX "lib") -# store all header files to install: -file(GLOB octomath_HDRS *.h *.hxx *.hpp) - -install(FILES ${octomath_HDRS} DESTINATION include/octomath) - -install(TARGETS octomath ${INSTALL_TARGETS_DEFAULT_ARGS}) +install(TARGETS octomath octomath-static ${INSTALL_TARGETS_DEFAULT_ARGS}) diff --git a/src/octovis/CMakeLists.txt b/src/octovis/CMakeLists.txt index 69da1b23..79f9c125 100755 --- a/src/octovis/CMakeLists.txt +++ b/src/octovis/CMakeLists.txt @@ -68,9 +68,15 @@ INCLUDE_DIRECTORIES( ) # Library target -add_library(octovis_library ${viewerlib_SRCS}) -target_link_libraries(octovis_library) -set_target_properties(octovis_library PROPERTIES OUTPUT_NAME octovis) +add_library(octovis-static STATIC ${viewerlib_SRCS}) +target_link_libraries(octovis-static) +set_target_properties(octovis-static PROPERTIES OUTPUT_NAME octovis) +SET_TARGET_PROPERTIES(octovis-static PROPERTIES PREFIX "lib") + +add_library(octovis-shared SHARED ${viewerlib_SRCS}) +target_link_libraries(octovis-shared) +set_target_properties(octovis-shared PROPERTIES OUTPUT_NAME octovis) + # Now add these generated files to the ADD_EXECUTABLE step # If this is NOT done, then the ui_*.h files will not be generated @@ -81,7 +87,7 @@ target_link_libraries(octovis ${QGLViewer_LIBRARIES} ${QT_LIBRARIES} octomap - octovis_library + octovis-shared ) # special handling of MacOS X: @@ -100,6 +106,7 @@ file(GLOB octovis_HDRS *.h *.hxx *.hpp) install(FILES ${octovis_HDRS} DESTINATION include/octovis) install(TARGETS octovis - octovis_library + octovis-static + octovis-shared ${INSTALL_TARGETS_DEFAULT_ARGS} )