Skip to content

Commit

Permalink
Support building as sub-project (#1553)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored Apr 10, 2021
1 parent 82028e3 commit bff098b
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 28 deletions.
27 changes: 16 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ if(POLICY CMP0053)
cmake_policy(SET CMP0053 NEW)
endif()

# Use DART_SOURCE/BINARY_DIR instead of CMAKE_SOURCE/BINARY_DIR to support the
# case that DART is built as a sub-project in another project.
set(DART_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(DART_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})

include(GNUInstallDirs)

# Variables used in Components.cmake
Expand All @@ -39,7 +44,7 @@ set(DART_ADDITIONAL_DOCUMENTATION_INSTALL_PATH
)

set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_MODULE_PATH "${DART_SOURCE_DIR}/cmake")

include(DARTMacros)

Expand Down Expand Up @@ -281,8 +286,8 @@ if(DART_VERBOSE)
elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "PROFILE")
message(STATUS "CXX_FLAGS_PROFILE: ${CMAKE_CXX_FLAGS_PROFILE}")
endif()
message(STATUS "CMAKE_SOURCE_DIR : ${CMAKE_SOURCE_DIR}")
message(STATUS "CMAKE_BINARY_DIR : ${CMAKE_BINARY_DIR}")
message(STATUS "DART_SOURCE_DIR : ${DART_SOURCE_DIR}")
message(STATUS "DART_BINARY_DIR : ${DART_BINARY_DIR}")
endif(DART_VERBOSE)

#===============================================================================
Expand Down Expand Up @@ -382,9 +387,9 @@ get_property(PACKAGE_INCLUDE_DIRS GLOBAL

# Generate the DART CMake Config and version files
include(CMakePackageConfigHelpers)
set(DART_CONFIG_IN ${CMAKE_SOURCE_DIR}/cmake/${PROJECT_NAME_UPPERCASE}Config.cmake.in)
set(DART_CONFIG_OUT ${CMAKE_BINARY_DIR}/${PROJECT_NAME_UPPERCASE}Config.cmake)
set(DART_VERSION_OUT ${CMAKE_BINARY_DIR}/cmake/${PROJECT_NAME_UPPERCASE}ConfigVersion.cmake)
set(DART_CONFIG_IN ${DART_SOURCE_DIR}/cmake/${PROJECT_NAME_UPPERCASE}Config.cmake.in)
set(DART_CONFIG_OUT ${DART_BINARY_DIR}/${PROJECT_NAME_UPPERCASE}Config.cmake)
set(DART_VERSION_OUT ${DART_BINARY_DIR}/cmake/${PROJECT_NAME_UPPERCASE}ConfigVersion.cmake)
if(DART_VERBOSE)
message(STATUS ${DART_CONFIG_OUT})
message(STATUS ${DART_VERSION_OUT})
Expand All @@ -406,8 +411,8 @@ install(
)

# Generate the DART pkg-config
set(PC_CONFIG_IN ${CMAKE_SOURCE_DIR}/cmake/dart.pc.in)
set(PC_CONFIG_OUT ${CMAKE_BINARY_DIR}/cmake/dart.pc)
set(PC_CONFIG_IN ${DART_SOURCE_DIR}/cmake/dart.pc.in)
set(PC_CONFIG_OUT ${DART_BINARY_DIR}/cmake/dart.pc)
set(PC_CONFIG_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig)
file(RELATIVE_PATH
RELATIVE_PATH_TO_INSTALL_PREFIX
Expand Down Expand Up @@ -483,14 +488,14 @@ if(CLANG_FORMAT_EXECUTABLE)
COMMAND ${CLANG_FORMAT_EXECUTABLE} -style=file -i ${formatting_files}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
DEPENDS ${CLANG_FORMAT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dart)
WORKING_DIRECTORY ${DART_SOURCE_DIR}/dart)

add_custom_target(check-format
COMMAND ${CMAKE_COMMAND} -E echo "Checking ${formatting_files_length} files... "
COMMAND ${CMAKE_SOURCE_DIR}/tools/check_format.sh ${CLANG_FORMAT_EXECUTABLE} ${formatting_files}
COMMAND ${DART_SOURCE_DIR}/tools/check_format.sh ${CLANG_FORMAT_EXECUTABLE} ${formatting_files}
COMMAND ${CMAKE_COMMAND} -E echo "Done."
DEPENDS ${CLANG_FORMAT_EXECUTABLE}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/dart)
WORKING_DIRECTORY ${DART_SOURCE_DIR}/dart)
else()
add_custom_target(format
COMMAND ${CMAKE_COMMAND} -E echo "Warning: Not found any source files to format.")
Expand Down
2 changes: 1 addition & 1 deletion cmake/Components.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ function(install_component_exports package_name)
endforeach()

configure_file(
"${CMAKE_SOURCE_DIR}/cmake/dart_Component.cmake.in"
"${DART_SOURCE_DIR}/cmake/dart_Component.cmake.in"
"${output_path}"
@ONLY)

Expand Down
2 changes: 1 addition & 1 deletion cmake/DARTMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ function(dart_build_target_in_source target)

set_target_properties(${target}
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
RUNTIME_OUTPUT_DIRECTORY "${DART_BINARY_DIR}/bin"
)

dart_format_add(${srcs})
Expand Down
12 changes: 6 additions & 6 deletions dart/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ if(MSVC AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
endif()

set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${DART_BINARY_DIR}/lib")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${DART_BINARY_DIR}/lib")

#===============================================================================
# Source directories
Expand Down Expand Up @@ -88,8 +88,8 @@ add_subdirectory(planning) # flann
add_subdirectory(utils) # tinyxml2, bullet
add_subdirectory(gui) # opengl, glut, bullet

set(DART_CONFIG_HPP_IN ${CMAKE_SOURCE_DIR}/dart/config.hpp.in)
set(DART_CONFIG_HPP_OUT ${CMAKE_BINARY_DIR}/dart/config.hpp)
set(DART_CONFIG_HPP_IN ${DART_SOURCE_DIR}/dart/config.hpp.in)
set(DART_CONFIG_HPP_OUT ${DART_BINARY_DIR}/dart/config.hpp)
if(DART_VERBOSE)
message(STATUS ${DART_CONFIG_HPP_OUT})
endif()
Expand Down Expand Up @@ -120,8 +120,8 @@ get_property(dart_core_sources GLOBAL PROPERTY DART_CORE_SOURCES)
dart_add_library(dart ${dart_core_headers} ${dart_core_sources})
target_include_directories(dart BEFORE
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${DART_SOURCE_DIR}>
$<BUILD_INTERFACE:${DART_BINARY_DIR}>
$<INSTALL_INTERFACE:include>
)
target_link_libraries(dart
Expand Down
4 changes: 2 additions & 2 deletions dart/external/odelcpsolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ set(component_name external-odelcpsolver)
dart_add_library(${target_name} ${hdrs} ${srcs})
target_include_directories(${target_name}
PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<BUILD_INTERFACE:${DART_SOURCE_DIR}>
$<BUILD_INTERFACE:${DART_BINARY_DIR}>
)
if(CMAKE_VERSION VERSION_LESS 3.8.2)
target_compile_options(${target_name} PUBLIC -std=c++14)
Expand Down
4 changes: 2 additions & 2 deletions examples/wam_ikfast/ikfast/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ target_compile_definitions(wamIk PUBLIC IKFAST_NO_MAIN IKFAST_CLIBRARY)
target_compile_options(wamIk PRIVATE -w)
set_target_properties(wamIk
PROPERTIES
LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${DART_BINARY_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${DART_BINARY_DIR}"
)
4 changes: 2 additions & 2 deletions extras/dartc/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/unittests/gtest/include)
include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/unittests/gtest)
include_directories(BEFORE SYSTEM ${DART_SOURCE_DIR}/unittests/gtest/include)
include_directories(BEFORE SYSTEM ${DART_SOURCE_DIR}/unittests/gtest)

function(dartc_add_test test_type target_name) # ARGN for source files

Expand Down
6 changes: 3 additions & 3 deletions unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#

# GoogleTest setup
include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/unittests/gtest/include)
include_directories(BEFORE SYSTEM ${CMAKE_SOURCE_DIR}/unittests/gtest)
include_directories(BEFORE SYSTEM ${DART_SOURCE_DIR}/unittests/gtest/include)
include_directories(BEFORE SYSTEM ${DART_SOURCE_DIR}/unittests/gtest)
add_library(gtest STATIC gtest/src/gtest-all.cc)
add_library(gtest_main STATIC gtest/src/gtest_main.cc)
target_link_libraries(gtest_main gtest)
Expand All @@ -41,7 +41,7 @@ if(NOT WIN32)
endif()
set_target_properties(
gtest PROPERTIES
ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
ARCHIVE_OUTPUT_DIRECTORY ${DART_BINARY_DIR}/lib
)

#===============================================================================
Expand Down

0 comments on commit bff098b

Please sign in to comment.