Skip to content

Commit

Permalink
Fix building with pagmo's optional dependencies (#1301)
Browse files Browse the repository at this point in the history
  • Loading branch information
jslee02 authored May 1, 2019
1 parent aeaf606 commit 4330d5e
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

* Fixed VskParker returning incorrect resource retriever: [#1300](https://github.com/dartsim/dart/pull/1300)

* Build

* Fixed building with pagmo's optional dependencies: [#1301](https://github.com/dartsim/dart/pull/1301)

#### Compilers Tested

* Linux
Expand Down
3 changes: 3 additions & 0 deletions cmake/DARTFindIPOPT.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

find_package(IPOPT 3.11.9 QUIET MODULE)

# HAVE_CSTDDEF is necessary to workaround this bug:
# https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684062
if(IPOPT_FOUND AND NOT TARGET IPOPT::ipopt)
add_library(IPOPT::ipopt INTERFACE IMPORTED)
set_target_properties(IPOPT::ipopt PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${IPOPT_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${IPOPT_LIBRARIES}"
INTERFACE_COMPILE_DEFINITIONS HAVE_CSTDDEF
)
endif()
71 changes: 71 additions & 0 deletions cmake/DARTFindpagmo.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,74 @@
# This file is provided under the "BSD-style" License

find_package(pagmo QUIET CONFIG)

dart_find_package(NLOPT)
dart_find_package(IPOPT)

if(TARGET Pagmo::pagmo)

# Check for pagmo optional dependencies
include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_DEFINITIONS "")
set(CMAKE_REQUIRED_LIBRARIES Pagmo::pagmo)
set(CMAKE_REQUIRED_FLAGS "-std=c++11 -w")

check_cxx_source_compiles(
"
#include <pagmo/config.hpp>
int main()
{
#if defined(PAGMO_WITH_NLOPT)
static_assert(true, \"Pagmo is build with NLOPT\");
#else
static_assert(false, \"Pagmo is NOT build with NLOPT\");
#endif
return 0;
}
"
PAGMO_BUILT_WITH_NLOPT
)

check_cxx_source_compiles(
"
#include <pagmo/config.hpp>
int main()
{
#if defined(PAGMO_WITH_IPOPT)
static_assert(true, \"Pagmo is build with IPOPT\");
#else
static_assert(false, \"Pagmo is NOT build with IPOPT\");
#endif
return 0;
}
"
PAGMO_BUILT_WITH_IPOPT
)

unset(CMAKE_REQUIRED_FLAGS)
unset(CMAKE_REQUIRED_LIBRARIES)
unset(CMAKE_REQUIRED_DEFINITIONS)

if(PAGMO_BUILT_WITH_NLOPT)
dart_find_package(NLOPT)
if(NOT TARGET NLOPT::nlopt)
message(STATUS
"The installed version of pagmo is built with nlopt, but nlopt is not "
"found. Please install nlopt to use dart-optimizer-pagmo."
)
set(pagmo_FOUND FALSE)
endif()
endif()

if(PAGMO_BUILT_WITH_IPOPT)
dart_find_package(IPOPT)
if(NOT TARGET IPOPT::ipopt)
message(STATUS
"The installed version of pagmo is built with ipopt, but ipopt is not "
"found. Please install ipopt to use dart-optimizer-pagmo."
)
set(pagmo_FOUND FALSE)
endif()
endif()

endif()
7 changes: 0 additions & 7 deletions dart/optimizer/ipopt/IpoptSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,8 @@
#ifndef DART_OPTIMIZER_IPOPT_IPOPTSOLVER_HPP_
#define DART_OPTIMIZER_IPOPT_IPOPTSOLVER_HPP_

//------------------------------------------------------------------------------
// Workaround for bug:
// (see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684062)
// This is fixed at IpOpt 3.11.4-1
#define HAVE_CSTDDEF
#include <coin/IpTNLP.hpp>
#include <coin/IpIpoptApplication.hpp>
#undef HAVE_CSTDDEF
//------------------------------------------------------------------------------

#include <memory>

Expand Down
3 changes: 1 addition & 2 deletions dart/optimizer/pagmo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Dependency checks
dart_find_package(NLOPT)
dart_find_package(pagmo)
dart_check_optional_package(pagmo "dart-optimizer-pagmo" "pagmo" "2.8")
if(pagmo_FOUND)
Expand All @@ -21,7 +20,7 @@ set(component_name optimizer-pagmo)

# Add target
dart_add_library(${target_name} ${hdrs} ${srcs})
target_link_libraries(${target_name} PUBLIC dart Pagmo::pagmo NLOPT::nlopt)
target_link_libraries(${target_name} PUBLIC dart Pagmo::pagmo)

# Thread
if(THREADS_HAVE_PTHREAD_ARG)
Expand Down
4 changes: 4 additions & 0 deletions dart/optimizer/pagmo/PagmoMultiObjectiveSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ PagmoMultiObjectiveSolver::~PagmoMultiObjectiveSolver()
}

//==============================================================================
#ifdef PAGMO_WITH_NLOPT
static pagmo::algorithm createNloptCobyla(
const PagmoMultiObjectiveSolver::Properties& properties)
{
Expand All @@ -95,6 +96,7 @@ static pagmo::algorithm createNloptCobyla(

return alg;
}
#endif

//==============================================================================
static pagmo::algorithm createMoead(
Expand All @@ -120,10 +122,12 @@ static pagmo::algorithm createPagmoAlgorithm(
{
switch (properties.mAlgorithm)
{
#ifdef PAGMO_WITH_NLOPT
case PagmoMultiObjectiveSolver::Algorithm::Local_nlopt_COBYLA:
{
return createNloptCobyla(properties);
}
#endif
case PagmoMultiObjectiveSolver::Algorithm::Global_MOEAD:
{
return createMoead(properties);
Expand Down
2 changes: 2 additions & 0 deletions dart/optimizer/pagmo/PagmoMultiObjectiveSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ class PagmoMultiObjectiveSolver : public MultiObjectiveSolver
/// Reference: https://esa.github.io/pagmo2/docs/algorithm_list.html
enum class Algorithm
{
#ifdef PAGMO_WITH_NLOPT
Local_nlopt_COBYLA,
#endif
Global_MOEAD,
Global_NSGA2,
};
Expand Down

0 comments on commit 4330d5e

Please sign in to comment.