diff --git a/CMakeLists.txt b/CMakeLists.txt index b5330130..424cf3f9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required( VERSION 3.5 FATAL_ERROR ) -project (urdfdom CXX C) +project (urdfdom CXX) set (URDF_MAJOR_VERSION 4) set (URDF_MINOR_VERSION 0) @@ -12,6 +12,8 @@ message (STATUS "${PROJECT_NAME} version ${URDF_VERSION}") include(GNUInstallDirs) +option(BUILD_APPS "Build applications" ON) +option(USE_VENDORED_DEPS "Use vendored dependencies" ON) option(APPEND_PROJECT_NAME_TO_INCLUDEDIR "When ON headers are installed to a folder ending with an extra ${PROJECT_NAME}. \ This avoids include directory search order issues when overriding this package @@ -27,8 +29,8 @@ if (NOT CMAKE_BUILD_TYPE) endif() # If compiler support symbol visibility, enable it. -include(CheckCCompilerFlag) -check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY) +include(CheckCXXCompilerFlag) +check_cxx_compiler_flag(-fvisibility=hidden HAS_VISIBILITY) if (HAS_VISIBILITY) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") endif() @@ -41,15 +43,17 @@ endif() # with MSVC being set off, but MSVCXX ON. if(MSVC OR MSVC90 OR MSVC10) set(MSVC ON) -endif (MSVC OR MSVC90 OR MSVC10) +endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(tinyxml2_vendor QUIET) -find_package(TinyXML2 REQUIRED) - find_package(urdfdom_headers 1.0 REQUIRED) -find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it. + +if(USE_VENDORED_DEPS) + find_package(tinyxml2_vendor QUIET) + find_package(console_bridge_vendor QUIET) # Provides console_bridge 0.4.0 on platforms without it. +endif() +find_package(TinyXML2 REQUIRED) find_package(console_bridge REQUIRED) # Control where libraries and executables are placed during the build @@ -67,7 +71,6 @@ add_subdirectory(urdf_parser) set(PKG_NAME ${PROJECT_NAME}) set(PKG_LIBRARIES urdfdom_sensor urdfdom_model_state urdfdom_model urdfdom_world) -set(PKG_DEPENDS urdfdom_headers) set(PKG_EXPORTS urdfdom) set(cmake_conf_file "cmake/urdfdom-config") include(CMakePackageConfigHelpers) @@ -79,6 +82,7 @@ write_basic_package_version_file( configure_package_config_file("${cmake_conf_file}.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}.cmake" INSTALL_DESTINATION ${CMAKE_CONFIG_INSTALL_DIR} + PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR ) install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${cmake_conf_file}.cmake" @@ -108,6 +112,6 @@ add_custom_target(uninstall message(STATUS "Configuration successful. Type make to compile urdfdom") -SET_DIRECTORY_PROPERTIES(PROPERTIES - ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/cmake/urdfdom-config.cmake - ADDITIONAL_MAKE_CLEAN_FILES ${CMAKE_BINARY_DIR}/cmake/pkgconfig/urdfdom.pc) +set_directory_properties(PROPERTIES + ADDITIONAL_CLEAN_FILES ${CMAKE_BINARY_DIR}/cmake/urdfdom-config.cmake + ADDITIONAL_CLEAN_FILES ${CMAKE_BINARY_DIR}/cmake/pkgconfig/urdfdom.pc) diff --git a/cmake/urdfdom-config.cmake.in b/cmake/urdfdom-config.cmake.in index ee84f41d..51802e08 100644 --- a/cmake/urdfdom-config.cmake.in +++ b/cmake/urdfdom-config.cmake.in @@ -5,47 +5,29 @@ if (@PKG_NAME@_CONFIG_INCLUDED) endif() set(@PKG_NAME@_CONFIG_INCLUDED TRUE) -set(CMAKE_MODULE_PATH_BACKUP_URDFDOM ${CMAKE_MODULE_PATH}) -list(APPEND CMAKE_MODULE_PATH "${@PROJECT_NAME@_DIR}") - -set(@PKG_NAME@_INCLUDE_DIRS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@") +set(@PKG_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@") +if(@APPEND_PROJECT_NAME_TO_INCLUDEDIR@) + list(APPEND @PKG_NAME@_INCLUDE_DIRS "@PACKAGE_CMAKE_INSTALL_INCLUDEDIR@/..") +endif() foreach(lib @PKG_LIBRARIES@) - set(onelib "${lib}-NOTFOUND") - set(onelibd "${lib}-NOTFOUND") - find_library(onelib ${lib} - PATHS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_LIBDIR@" - NO_DEFAULT_PATH) - find_library(onelibd ${lib}d - PATHS "${@PROJECT_NAME@_DIR}/@RELATIVE_PATH_CMAKE_DIR_TO_PREFIX@/@CMAKE_INSTALL_LIBDIR@" - NO_DEFAULT_PATH) - if(onelib-NOTFOUND AND onelibd-NOTFOUND) - message(FATAL_ERROR "Library '${lib}' in package @PKG_NAME@ is not installed properly") - endif() - if(onelib AND onelibd) - list(APPEND @PKG_NAME@_LIBRARIES $<$>:${onelib}>) - list(APPEND @PKG_NAME@_LIBRARIES $<$:${onelibd}>) - else() - if(onelib) - list(APPEND @PKG_NAME@_LIBRARIES ${onelib}) - else() - list(APPEND @PKG_NAME@_LIBRARIES ${onelibd}) - endif() - endif() list(APPEND @PKG_NAME@_TARGETS @PROJECT_NAME@::${lib}) endforeach() -find_package(tinyxml2_vendor QUIET) -foreach(dep @PKG_DEPENDS@) - if(NOT ${dep}_FOUND) - find_package(${dep}) - endif() - list(APPEND @PKG_NAME@_INCLUDE_DIRS ${${dep}_INCLUDE_DIRS}) - list(APPEND @PKG_NAME@_LIBRARIES ${${dep}_LIBRARIES}) -endforeach() +include(CMakeFindDependencyMacro) +if(@USE_VENDORED_DEPS@) + find_dependency(tinyxml2_vendor QUIET) + find_dependency(console_bridge_vendor QUIET) +else() + find_dependency(TinyXML2 REQUIRED) + find_dependency(console_bridge REQUIRED) +endif() + +find_dependency(urdfdom_headers REQUIRED) +list(APPEND @PKG_NAME@_INCLUDE_DIRS "${urdfdom_headers_INCLUDE_DIRS}") foreach(exp @PKG_EXPORTS@) include(${@PROJECT_NAME@_DIR}/${exp}Export.cmake) endforeach() -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH_BACKUP_URDFDOM}) +set(@PKG_NAME@_LIBRARIES ${@PKG_NAME@_TARGETS}) diff --git a/urdf_parser/CMakeLists.txt b/urdf_parser/CMakeLists.txt index 20a6a050..610f6e94 100644 --- a/urdf_parser/CMakeLists.txt +++ b/urdf_parser/CMakeLists.txt @@ -22,6 +22,9 @@ macro(add_urdfdom_library) set_target_properties(${add_urdfdom_library_LIBNAME} PROPERTIES DEFINE_SYMBOL URDFDOM_EXPORTS SOVERSION ${URDF_MAJOR_MINOR_VERSION}) + if(MSVC) + target_compile_definitions(${add_urdfdom_library_LIBNAME} PUBLIC _USE_MATH_DEFINES) + endif() endmacro() if(TARGET console_bridge::console_bridge) @@ -80,41 +83,44 @@ target_link_libraries(urdf_parser INTERFACE urdfdom::urdfdom_world) # -------------------------------- +if(BUILD_APPS) + add_executable(check_urdf src/check_urdf.cpp) + target_include_directories(check_urdf PUBLIC include) + target_link_libraries(check_urdf urdfdom_model urdfdom_world) + + # Deprecated executable + add_executable(urdf_to_graphiz src/urdf_to_graphviz.cpp) + target_link_libraries(urdf_to_graphiz urdfdom_model) + + add_executable(urdf_to_graphviz src/urdf_to_graphviz.cpp) + target_include_directories(urdf_to_graphviz PUBLIC include) + target_link_libraries(urdf_to_graphviz urdfdom_model) + + # urdf_mem_test is a binary for testing, not a unit test + add_executable(urdf_mem_test test/memtest.cpp) + target_include_directories(urdf_mem_test PUBLIC include) + target_link_libraries(urdf_mem_test urdfdom_model) +endif() -add_executable(check_urdf src/check_urdf.cpp) -target_include_directories(check_urdf PUBLIC include) -target_link_libraries(check_urdf urdfdom_model urdfdom_world) - -# Deprecated executable -add_executable(urdf_to_graphiz src/urdf_to_graphviz.cpp) -target_link_libraries(urdf_to_graphiz urdfdom_model) - -add_executable(urdf_to_graphviz src/urdf_to_graphviz.cpp) -target_include_directories(urdf_to_graphviz PUBLIC include) -target_link_libraries(urdf_to_graphviz urdfdom_model) - -# urdf_mem_test is a binary for testing, not a unit test -add_executable(urdf_mem_test test/memtest.cpp) -target_include_directories(urdf_mem_test PUBLIC include) -target_link_libraries(urdf_mem_test urdfdom_model) - -include(CTest) if(BUILD_TESTING) + include(CTest) # TODO: check Shane's comment https://github.com/ros/urdfdom/pull/157/files#r664960227 add_subdirectory(test) endif() -INSTALL( - TARGETS - check_urdf - urdf_to_graphiz - urdf_to_graphviz - urdf_mem_test - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} -) -INSTALL( +if(BUILD_APPS) + install( + TARGETS + check_urdf + urdf_to_graphiz + urdf_to_graphviz + urdf_mem_test + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() +install( TARGETS urdfdom_model urdfdom_world @@ -134,4 +140,4 @@ install( FILE "urdfdomExport.cmake" ) -INSTALL(DIRECTORY include/urdf_parser DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) +install(DIRECTORY include/urdf_parser DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})