From 3e767d13eeebc6f7e728b035cd7d142625841939 Mon Sep 17 00:00:00 2001 From: Jeongseok Lee Date: Fri, 5 Apr 2024 09:27:19 -0700 Subject: [PATCH] w4 --- CMakeLists.txt | 64 +++++++++++--------- dart/common/Logging.hpp | 7 +-- dart/config.hpp.in | 2 + dart/constraint/BoxedLcpConstraintSolver.cpp | 34 +++-------- dart/constraint/DantzigLCPSolver.cpp | 2 +- dart/constraint/PGSLCPSolver.cpp | 2 +- pixi.toml | 7 +++ 7 files changed, 54 insertions(+), 64 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e2ef2722ec21..f225f09ac767f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -162,24 +162,11 @@ endif() #=============================================================================== # Build type settings #=============================================================================== -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: Debug | Release | RelWithDebInfo | MinSizeRel" FORCE) -endif() -string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UPPERCASE) - -set(DART_BUILD_MODE_DEBUG FALSE) -set(DART_BUILD_MODE_RELEASE FALSE) - -if("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "DEBUG") - set(DART_BUILD_MODE_DEBUG TRUE) -elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELEASE") - set(DART_BUILD_MODE_RELEASE TRUE) -elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "RELWITHDEBINFO") - set(DART_BUILD_MODE_RELEASE TRUE) -elseif("${CMAKE_BUILD_TYPE_UPPERCASE}" STREQUAL "MINSIZEREL") - set(DART_BUILD_MODE_RELEASE TRUE) -else() - message(WARNING "CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} unknown. Valid options are: Debug | Release | RelWithDebInfo | MinSizeRel") +if(NOT CMAKE_CONFIGURATION_TYPES) + if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + endif() endif() # Active log level: @@ -191,14 +178,33 @@ endif() # - ERROR: To enable log with DART_ERROR() and below # - FATAL: To enable log with DART_FATAL() # - OFF: To turn off all the logs -if(DART_BUILD_MODE_DEBUG) - set(DART_ACTIVE_LOG_LEVEL "DEBUG" CACHE STRING "Compile time active log level to enable") +if(NOT DART_ACTIVE_LOG_LEVEL) + if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DART_ACTIVE_LOG_LEVEL "DEBUG" CACHE STRING "Compile time active log level to enable") + else() + set(DART_ACTIVE_LOG_LEVEL "INFO" CACHE STRING "Compile time active log level to enable") + endif() + set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF) +endif() +if(DART_ACTIVE_LOG_LEVEL STREQUAL "TRACE") + set(DART_ACTIVE_LOG_LEVEL_VALUE 0) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "DEBUG") + set(DART_ACTIVE_LOG_LEVEL_VALUE 1) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "INFO") + set(DART_ACTIVE_LOG_LEVEL_VALUE 2) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "WARN") + set(DART_ACTIVE_LOG_LEVEL_VALUE 3) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "ERROR") + set(DART_ACTIVE_LOG_LEVEL_VALUE 4) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "FATAL") + set(DART_ACTIVE_LOG_LEVEL_VALUE 5) +elseif(DART_ACTIVE_LOG_LEVEL STREQUAL "OFF") + set(DART_ACTIVE_LOG_LEVEL_VALUE 6) else() - set(DART_ACTIVE_LOG_LEVEL "INFO" CACHE STRING "Compile time active log level to enable") + message(FATAL_ERROR "Unknown DART_ACTIVE_LOG_LEVEL: ${DART_ACTIVE_LOG_LEVEL}") endif() -set_property(CACHE DART_ACTIVE_LOG_LEVEL PROPERTY STRINGS TRACE DEBUG INFO WARN ERROR FATAL OFF) -if(DART_BUILD_MODE_DEBUG) +if(NOT CMAKE_CONFIGURATION_TYPES AND CMAKE_BUILD_TYPE STREQUAL "Debug") option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) else() option(DART_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON) @@ -355,14 +361,12 @@ if(DART_VERBOSE) message(STATUS "Build gui::osg : ${DART_BUILD_GUI_OSG}") message(STATUS "Install path : ${CMAKE_INSTALL_PREFIX}") message(STATUS "CXX_FLAGS : ${CMAKE_CXX_FLAGS}") - if(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "RELEASE") - message(STATUS "CXX_FLAGS_RELEASE: ${CMAKE_CXX_FLAGS_RELEASE}") - elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "DEBUG") - message(STATUS "CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}") - elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "RELWITHDEBINFO") + if(NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "CXX_FLAGS_RELEASE : ${CMAKE_CXX_FLAGS_RELEASE}") + message(STATUS "CXX_FLAGS_DEBUG : ${CMAKE_CXX_FLAGS_DEBUG}") + message(STATUS "CXX_FLAGS_MINSIZEREL : ${CXX_FLAGS_MINSIZEREL}") message(STATUS "CXX_FLAGS_RELWITHDEBINFO: ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}") - elseif(${CMAKE_BUILD_TYPE_UPPERCASE} STREQUAL "PROFILE") - message(STATUS "CXX_FLAGS_PROFILE: ${CMAKE_CXX_FLAGS_PROFILE}") + message(STATUS "CXX_FLAGS_PROFILE : ${CMAKE_CXX_FLAGS_PROFILE}") endif() message(STATUS "DART_SOURCE_DIR : ${DART_SOURCE_DIR}") message(STATUS "DART_BINARY_DIR : ${DART_BINARY_DIR}") diff --git a/dart/common/Logging.hpp b/dart/common/Logging.hpp index 2ec2251c149e8..4812a0efa4f09 100644 --- a/dart/common/Logging.hpp +++ b/dart/common/Logging.hpp @@ -33,6 +33,8 @@ #ifndef DART_COMMON_LOGGING_HPP_ #define DART_COMMON_LOGGING_HPP_ +#include + // clang-format off #define DART_LOG_LEVEL_TRACE 0 #define DART_LOG_LEVEL_DEBUG 1 @@ -43,11 +45,6 @@ #define DART_LOG_LEVEL_OFF 6 // clang-format on -// Default active log level -#if !defined(DART_ACTIVE_LOG_LEVEL) - #define DART_ACTIVE_LOG_LEVEL DART_LOG_LEVEL_INFO -#endif - #if DART_ACTIVE_LOG_LEVEL <= DART_LOG_LEVEL_TRACE #define DART_TRACE(...) ::dart::common::trace(__VA_ARGS__) #else diff --git a/dart/config.hpp.in b/dart/config.hpp.in index 2f8317d6aaf8d..dc521ec766206 100644 --- a/dart/config.hpp.in +++ b/dart/config.hpp.in @@ -92,3 +92,5 @@ #cmakedefine01 DART_USE_SYSTEM_IMGUI #cmakedefine01 DART_BUILD_PROFILE + +#define DART_ACTIVE_LOG_LEVEL @DART_ACTIVE_LOG_LEVEL_VALUE@ diff --git a/dart/constraint/BoxedLcpConstraintSolver.cpp b/dart/constraint/BoxedLcpConstraintSolver.cpp index fc8d1b48685ee..53260cb5f5166 100644 --- a/dart/constraint/BoxedLcpConstraintSolver.cpp +++ b/dart/constraint/BoxedLcpConstraintSolver.cpp @@ -51,33 +51,7 @@ namespace constraint { namespace { -//============================================================================== #ifndef NDEBUG -bool isSymmetric(std::size_t n, double* A) -{ - std::size_t nSkip = dPAD(n); - for (std::size_t i = 0; i < n; ++i) { - for (std::size_t j = 0; j < n; ++j) { - if (std::abs(A[nSkip * i + j] - A[nSkip * j + i]) > 1e-6) { - std::cout << "A: " << std::endl; - for (std::size_t k = 0; k < n; ++k) { - for (std::size_t l = 0; l < nSkip; ++l) { - std::cout << std::setprecision(4) << A[k * nSkip + l] << " "; - } - std::cout << std::endl; - } - - std::cout << "A(" << i << ", " << j << "): " << A[nSkip * i + j] - << std::endl; - std::cout << "A(" << j << ", " << i << "): " << A[nSkip * j + i] - << std::endl; - return false; - } - } - } - - return true; -} //============================================================================== bool isSymmetric(std::size_t n, double* A, std::size_t begin, std::size_t end) @@ -107,7 +81,13 @@ bool isSymmetric(std::size_t n, double* A, std::size_t begin, std::size_t end) } //============================================================================== -void print( +bool isSymmetric(std::size_t n, double* A) +{ + return isSymmetric(n, A, 0, n - 1); +} + +//============================================================================== +[[maybe_unused]] void print( std::size_t n, double* A, double* x, diff --git a/dart/constraint/DantzigLCPSolver.cpp b/dart/constraint/DantzigLCPSolver.cpp index 45834f9854f43..b2d01375fa062 100644 --- a/dart/constraint/DantzigLCPSolver.cpp +++ b/dart/constraint/DantzigLCPSolver.cpp @@ -105,7 +105,7 @@ bool isSymmetric( } //============================================================================== -void print( +[[maybe_unused]] void print( std::size_t _n, double* _A, double* _x, diff --git a/dart/constraint/PGSLCPSolver.cpp b/dart/constraint/PGSLCPSolver.cpp index e4eff78553a54..f0f14a2830ada 100644 --- a/dart/constraint/PGSLCPSolver.cpp +++ b/dart/constraint/PGSLCPSolver.cpp @@ -106,7 +106,7 @@ bool isSymmetric( } //============================================================================== -void print( +[[maybe_unused]] void print( std::size_t _n, double* _A, double* _x, diff --git a/pixi.toml b/pixi.toml index a660b0f19fb16..9467815b90da7 100644 --- a/pixi.toml +++ b/pixi.toml @@ -46,6 +46,7 @@ install-local = { cmd = "cmake --install build --prefix $CONDA_PREFIX", depends_ ] } configure = { cmd = "cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Release -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON" } +configure-dev = { cmd = "cmake -G Ninja -S . -B build -DCMAKE_BUILD_TYPE=Debug -DDART_VERBOSE=ON -DDART_USE_SYSTEM_IMGUI=ON" } lint = { cmd = "cmake --build build --target format && black . && isort .", depends_on = [ "configure", @@ -57,6 +58,9 @@ check-lint = { cmd = "cmake --build build --target check-format && black . --che build = { cmd = "cmake --build build -j --target all", depends_on = [ "configure", ] } +build-dev = { cmd = "cmake --build build -j --target all", depends_on = [ + "configure-dev", +] } build-tests = { cmd = "cmake --build build -j --target tests", depends_on = [ "configure", ] } @@ -151,6 +155,9 @@ check-lint = { cmd = "black . --check && isort . --check", depends_on = [ build = { cmd = "cmake --build build --config Release -j", depends_on = [ "configure", ] } +build-dev = { cmd = "cmake --build build --config Debug -j", depends_on = [ + "configure", +] } build-tests = { cmd = "cmake --build build --config Release -j --target tests", depends_on = [ "configure", ] }