Skip to content

Commit

Permalink
[v7] Initial setup
Browse files Browse the repository at this point in the history
(cherry picked from commit f8c5108)
  • Loading branch information
jslee02 committed Mar 17, 2024
1 parent c94c5bc commit f2ecbba
Show file tree
Hide file tree
Showing 38 changed files with 1,068 additions and 53 deletions.
6 changes: 4 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,12 @@ IncludeCategories:
Priority: 31
- Regex: '^<dart\/common\/.*\.h(pp)?>$'
Priority: 32
- Regex: '^<dart\/.*\.h(pp)?>$'
- Regex: '^<dart\/common\/.*\.h(pp)?>$'
Priority: 33
- Regex: '^<dart\/.*\.h(pp)?>$'
Priority: 40
- Regex: '^<dart\/external\/.*\.h(pp)?>$'
Priority: 34
Priority: 50

# 3rd-party headers
- Regex: '^<.*\.h(pp)?>$'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
COMPILER: clang
BUILD_TYPE: ${{ matrix.build_type }}
BUILD_DARTPY: ON
DART_USE_SYSTEM_ENTT: ON
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -64,4 +65,3 @@ jobs:
- name: Test DART and dartpy
run: |
pixi run build
4 changes: 2 additions & 2 deletions .github/workflows/ci_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:

- uses: johnwason/vcpkg-action@v6
with:
pkgs: assimp ccd eigen3 fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
pkgs: assimp ccd eigen3 entt fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand All @@ -61,6 +61,7 @@ jobs:
-DDART_MSVC_DEFAULT_OPTIONS=ON ^
-DDART_VERBOSE=ON ^
-DBUILD_SHARED_LIBS=${{ matrix.build_shared_libs }} ^
-DDART_USE_SYSTEM_ENTT=ON ^
|| exit /b
cmake ^
--build build ^
Expand Down Expand Up @@ -93,4 +94,3 @@ jobs:
- name: Test DART and dartpy
run: |
pixi run build
2 changes: 1 addition & 1 deletion .github/workflows/publish_dartpy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ jobs:
if: ${{ matrix.os == 'windows-latest' && (matrix.release_only == false || github.ref == 'refs/heads/main') }}
uses: johnwason/vcpkg-action@v6
with:
pkgs: assimp ccd eigen3 fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
pkgs: assimp ccd eigen3 entt fcl fmt spdlog bullet3 coin-or-ipopt freeglut glfw3 nlopt ode opengl osg pagmo2 tinyxml2 urdfdom
triplet: x64-windows
revision: "2024.02.14"
github-binarycache: true
Expand Down
1 change: 1 addition & 0 deletions Brewfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ brew 'octomap'
brew 'ode'
#brew 'open-scene-graph' # disabled until 3.7.0 is released
brew 'pagmo'
brew 'skypjack/entt/entt'
brew 'spdlog'
brew 'tinyxml2'
brew 'urdfdom'
Expand Down
22 changes: 13 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set(CMAKE_DEBUG_POSTFIX "d")
set(CMAKE_MODULE_PATH "${DART_SOURCE_DIR}/cmake")

include(DARTMacros)
include(dart_defs)

# CMake component helper. It uses the following variables:
# - LIBRARY_INSTALL_DIR
Expand Down Expand Up @@ -73,13 +74,13 @@ set(DART_PKG_EXTERNAL_DEPS "eigen, ccd, fcl, assimp")
#===============================================================================
# Build options
#===============================================================================
option(DART_VERBOSE "Whether print detailed information in CMake process" OFF)
dart_option(DART_VERBOSE "Whether print detailed information in CMake process" OFF)
if(MSVC)
set(DART_RUNTIME_LIBRARY "/MD" CACHE STRING "BaseName chosen by the user at CMake configure time")
set_property(CACHE DART_RUNTIME_LIBRARY PROPERTY STRINGS /MD /MT)
option(DART_MSVC_DEFAULT_OPTIONS "Build DART with default Visual Studio options" OFF)
dart_option(DART_MSVC_DEFAULT_OPTIONS "Build DART with default Visual Studio options" OFF)
else()
option(BUILD_SHARED_LIBS "Build shared libraries" ON)
dart_option(BUILD_SHARED_LIBS "Build shared libraries" ON)
endif()
# Warning: DART_ENABLE_SIMD should be ON only when you build DART and the DART
# dependent projects on the same machine. If this option is on, then compile
Expand All @@ -88,19 +89,20 @@ endif()
# local machines are different then the projects will be built with different
# compile options, which may cause runtime errors especially memory alignment
# errors.
option(DART_ENABLE_SIMD
dart_option(DART_ENABLE_SIMD
"Build DART with all SIMD instructions on the current local machine" OFF)
option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
option(DART_BUILD_DARTPY "Build dartpy" ON)
option(DART_CODECOV "Turn on codecov support" OFF)
option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
dart_option(DART_BUILD_GUI_OSG "Build osgDart library" ON)
dart_option(DART_BUILD_DARTPY "Build dartpy" ON)
dart_option(DART_CODECOV "Turn on codecov support" OFF)
dart_option(DART_FAST_DEBUG "Add -O1 option for DEBUG mode build" OFF)
# GCC and Clang add ANSI-formatted colors when they detect the output medium is a
# terminal. However, this doesn't work in some cases such as when the makefile is
# invoked by Ninja. DART_FORCE_COLORED_OUTPUT can be used in this case to enforce
# to always generate ANSI-formatted colors regardless of the output medium types.
# See: https://medium.com/@alasher/colored-c-compiler-output-with-ninja-clang-gcc-10bfe7f2b949
option(DART_FORCE_COLORED_OUTPUT
dart_option(DART_FORCE_COLORED_OUTPUT
"Always produce ANSI-colored output (GNU/Clang only)." OFF)
dart_option(DART_USE_SYSTEM_ENTT "Use system EnTT" OFF)

#===============================================================================
# Print intro
Expand All @@ -111,6 +113,8 @@ message(STATUS " DART ${DART_VERSION}")
message(STATUS "============================================")
message(STATUS "")

dart_print_options()

# Print build tool information
message(STATUS "[ Build Tools ]")
message(STATUS "- CMake : ${CMAKE_VERSION}")
Expand Down
3 changes: 3 additions & 0 deletions cmake/DARTConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ endfunction()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

# TODO: Improve the include mechanism
include(dart_v7Targets)

# Default component: dart
list(APPEND @PROJECT_NAME_UPPERCASE@_FIND_COMPONENTS dart)

Expand Down
6 changes: 6 additions & 0 deletions cmake/DARTFindDependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ dart_check_required_package(fmt "libfmt")
dart_find_package(Eigen3)
dart_check_required_package(EIGEN3 "eigen3")

# Entt
if(DART_USE_SYSTEM_ENTT)
dart_find_package(EnTT)
dart_check_required_package(EnTT "EnTT")
endif()

# CCD
dart_find_package(ccd)
dart_check_required_package(ccd "libccd")
Expand Down
9 changes: 9 additions & 0 deletions cmake/DARTFindEnTT.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2011-2024, The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/main/LICENSE
#
# This file is provided under the "BSD-style" License

find_package(EnTT QUIET CONFIG)
224 changes: 224 additions & 0 deletions cmake/dart_defs.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# Copyright (c) The DART development contributors
# All rights reserved.
#
# The list of contributors can be found at:
# https://github.com/dartsim/dart/blob/master/LICENSE
#
# This file is provided under the following "BSD-style" License:
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
# conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

# dart_get_max(var [value1 value2...])
function(dart_get_max var)
set(first YES)
set(choice NO)
foreach(item ${ARGN})
if(first)
set(choice ${item})
set(first NO)
elseif(choice LESS ${item})
set(choice ${item})
endif()
endforeach(item)
set(${var} ${choice} PARENT_SCOPE)
endfunction()

# dart_get_max_string_length(var [value1 value2...])
function(dart_get_max_string_length var)
foreach(item ${ARGN})
string(LENGTH ${item} length)
list(APPEND list ${length})
endforeach()
dart_get_max(choice ${list})
set(${var} ${choice} PARENT_SCOPE)
endfunction()

# cmake-format: off
# dart_option(<variable> "<help_text>" <value>)
# cmake-format: on
function(dart_option variable help_text default_value)
set_property(
GLOBAL PROPERTY DART_DETAIL_PROPERTY_OPTION_VARIABLE "${variable}" APPEND
)
set_property(
GLOBAL PROPERTY DART_DETAIL_property_option_help_text "${help_text}" APPEND
)
set_property(
GLOBAL PROPERTY DART_DETAIL_property_option_default_value "${default_value}"
APPEND
)

# Add option
option(${variable} ${help_text} ${default_value})

# Normalize boolean value variants (e.g. 1/0, On/Off, TRUE/FALSE) to ON/OFF
if(${variable})
set(${variable} ON PARENT_SCOPE)
else()
set(${variable} OFF PARENT_SCOPE)
endif()

endfunction()

# cmake-format: off
# dart_print_options()
# cmake-format: on
function(dart_print_options)
# Print the header
message(STATUS "[ Options ]")

get_property(
option_variables GLOBAL PROPERTY DART_DETAIL_PROPERTY_OPTION_VARIABLE
)
get_property(
option_help_texts GLOBAL PROPERTY DART_DETAIL_property_option_help_text
)
get_property(
option_default_values GLOBAL
PROPERTY DART_DETAIL_property_option_default_value
)

dart_get_max_string_length(option_variable_max_len ${option_variables})
list(LENGTH option_variables option_count)
math(EXPR option_count "${option_count} - 1")
foreach(val RANGE ${option_count})
list(GET option_variables ${val} option_variable)
list(GET option_default_values ${val} option_default_value)

set(option_str "- ${option_variable}")
set(spaces "")
string(LENGTH ${option_variable} option_variable_len)
math(EXPR space_count "${option_variable_max_len} - ${option_variable_len}")
foreach(loop_var RANGE ${space_count})
set(option_str "${option_str} ")
endforeach()

set(option_str "${option_str}: ${${option_variable}}")

if(${option_variable} STREQUAL option_default_value)
set(option_str "${option_str} [default]")
endif()

message(STATUS "${option_str}")
endforeach()

message(STATUS "")
endfunction()

function(dart_library)
set(prefix _ARG)
set(options
GLOB_HEADERS
GLOB_SOURCES
)
set(oneValueArgs
NAME
)
set(multiValueArgs
HEADERS
SOURCES
PUBLIC_LINK_LIBRARIES
PRIVATE_LINK_LIBRARIES
PUBLIC_COMPILE_DEFINITIONS
PRIVATE_COMPILE_DEFINITIONS
)
cmake_parse_arguments(
"${prefix}" "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}
)

# Get the current directory relative to the root of the project
# assuming that dart/* is the root of the source tree
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" relative_path ${CMAKE_CURRENT_SOURCE_DIR})

if(${_ARG_GLOB_HEADERS})
file(GLOB_RECURSE headers "*.hpp")
list(APPEND _ARG_HEADERS ${headers})
endif()

if(${_ARG_GLOB_SOURCES})
file(GLOB_RECURSE sources "*.cpp")
list(APPEND _ARG_SOURCES ${sources})
endif()

add_library(${_ARG_NAME}
${_ARG_HEADERS}
${_ARG_SOURCES}
)

target_include_directories(${_ARG_NAME} PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

target_compile_features(${_ARG_NAME} PUBLIC cxx_std_17)

target_link_libraries(${_ARG_NAME}
PUBLIC
${_ARG_PUBLIC_LINK_LIBRARIES}
PRIVATE
${_ARG_PRIVATE_LINK_LIBRARIES}
)

target_compile_definitions(${_ARG_NAME}
PUBLIC
${_ARG_PUBLIC_COMPILE_DEFINITIONS}
PRIVATE
${_ARG_PRIVATE_COMPILE_DEFINITIONS}
)

set_target_properties(${_ARG_NAME} PROPERTIES
OUTPUT_NAME dart-${_ARG_NAME}
)

include(GNUInstallDirs)

foreach(header ${_ARG_HEADERS})
# Compute the relative path of each header from the root_dir
file(RELATIVE_PATH rel_path "${CMAKE_SOURCE_DIR}" "${header}")
get_filename_component(rel_dir "${rel_path}" DIRECTORY)

# Install the file to the destination, preserving the directory structure
install(
FILES "${header}"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${rel_dir}"
)
endforeach()

install(
TARGETS ${_ARG_NAME}
EXPORT dart_${_ARG_NAME}Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(
EXPORT dart_${_ARG_NAME}Targets
NAMESPACE DART::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake
)

dart_format_add(${_ARG_HEADERS} ${_ARG_SOURCES})

endfunction()
Loading

0 comments on commit f2ecbba

Please sign in to comment.