From 8cef0f96549009d373477bd9143762296ac5943b Mon Sep 17 00:00:00 2001 From: ManifoldFR Date: Mon, 7 Oct 2024 14:38:42 +0200 Subject: [PATCH 1/6] Add FindIpopt.cmake module --- find-external/Ipopt/FindIpopt.cmake | 47 +++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 find-external/Ipopt/FindIpopt.cmake diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake new file mode 100644 index 000000000..a6c8e6384 --- /dev/null +++ b/find-external/Ipopt/FindIpopt.cmake @@ -0,0 +1,47 @@ +# Copyright 2024 CNRS INRIA +# +# Author: Wilson Jallet +# +# Adapted from: https://github.com/casadi/casadi/blob/main/cmake/FindIPOPT.cmake +# +# Uses the modern PkgConfig CMake module helpers to find an installed version of Ipopt, +# for which a CMake shared imported library target is created with the required includes and compile options in its link interface. +# +find_package(Ipopt CONFIG QUIET) + +if(Ipopt_FOUND) + message(DEBUG "Found Ipopt (using IpoptConfig.cmake or ipopt-config.cmake)") +else() + find_package(PkgConfig QUIET) + if(NOT PKG_CONFIG_FOUND) + message(FATAL_ERROR "pkg-config not found!") + endif() + pkg_check_modules(Ipopt REQUIRED ipopt) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args( + Ipopt + FAIL_MESSAGE DEFAULT_MSG + REQUIRED_VARS Ipopt_INCLUDE_DIRS Ipopt_LIBRARIES + VERSION_VAR Ipopt_VERSION) + + message(STATUS " Ipopt library dirs: ${Ipopt_LIBRARY_DIRS}") + message(STATUS " Ipopt include dirs: ${Ipopt_INCLUDE_DIRS}") + add_library(ipopt SHARED IMPORTED) + find_library( + ipopt_lib_path + NAMES ipopt + PATHS ${Ipopt_LIBRARY_DIRS}) + message(STATUS " Ipopt library ipopt found at ${ipopt_lib_path}") + set_target_properties(ipopt PROPERTIES IMPORTED_LOCATION ${ipopt_lib_path}) + target_include_directories(ipopt INTERFACE ${Ipopt_INCLUDE_DIRS}) + + if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") + + else() + target_compile_definitions(ipopt INTERFACE HAVE_CSTDDEF) + endif() + target_compile_options(ipopt INTERFACE ${Ipopt_CFLAGS_OTHER}) + + add_library(Ipopt::Ipopt ALIAS ipopt) +endif() From 8f37e55f2f6e310933a4a99c8cf25a53afeafe4f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 7 Oct 2024 12:46:52 +0000 Subject: [PATCH 2/6] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- find-external/Ipopt/FindIpopt.cmake | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake index a6c8e6384..971edd717 100644 --- a/find-external/Ipopt/FindIpopt.cmake +++ b/find-external/Ipopt/FindIpopt.cmake @@ -4,8 +4,9 @@ # # Adapted from: https://github.com/casadi/casadi/blob/main/cmake/FindIPOPT.cmake # -# Uses the modern PkgConfig CMake module helpers to find an installed version of Ipopt, -# for which a CMake shared imported library target is created with the required includes and compile options in its link interface. +# Uses the modern PkgConfig CMake module helpers to find an installed version of +# Ipopt, for which a CMake shared imported library target is created with the +# required includes and compile options in its link interface. # find_package(Ipopt CONFIG QUIET) From fd354bef704592b5e862cfcfe5bf67b802a5a634 Mon Sep 17 00:00:00 2001 From: ManifoldFR Date: Mon, 7 Oct 2024 15:05:46 +0200 Subject: [PATCH 3/6] add license mention --- find-external/Ipopt/FindIpopt.cmake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake index 971edd717..1ec96db19 100644 --- a/find-external/Ipopt/FindIpopt.cmake +++ b/find-external/Ipopt/FindIpopt.cmake @@ -2,7 +2,9 @@ # # Author: Wilson Jallet # -# Adapted from: https://github.com/casadi/casadi/blob/main/cmake/FindIPOPT.cmake +# Adapted from: +# https://github.com/casadi/casadi/blob/main/cmake/FindIPOPT.cmake, LGPL 3.0 +# License # # Uses the modern PkgConfig CMake module helpers to find an installed version of # Ipopt, for which a CMake shared imported library target is created with the From 8df20474ef137e4f735835e7e38d3e495ba8c32e Mon Sep 17 00:00:00 2001 From: Wilson Date: Mon, 7 Oct 2024 15:06:31 +0200 Subject: [PATCH 4/6] Apply suggestions from code review Co-authored-by: Guilhem Saurel --- find-external/Ipopt/FindIpopt.cmake | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake index 1ec96db19..2dd20a792 100644 --- a/find-external/Ipopt/FindIpopt.cmake +++ b/find-external/Ipopt/FindIpopt.cmake @@ -15,10 +15,7 @@ find_package(Ipopt CONFIG QUIET) if(Ipopt_FOUND) message(DEBUG "Found Ipopt (using IpoptConfig.cmake or ipopt-config.cmake)") else() - find_package(PkgConfig QUIET) - if(NOT PKG_CONFIG_FOUND) - message(FATAL_ERROR "pkg-config not found!") - endif() + find_package(PkgConfig REQUIRED) pkg_check_modules(Ipopt REQUIRED ipopt) include(FindPackageHandleStandardArgs) @@ -35,13 +32,11 @@ else() ipopt_lib_path NAMES ipopt PATHS ${Ipopt_LIBRARY_DIRS}) - message(STATUS " Ipopt library ipopt found at ${ipopt_lib_path}") + message(STATUS " Ipopt library found at ${ipopt_lib_path}") set_target_properties(ipopt PROPERTIES IMPORTED_LOCATION ${ipopt_lib_path}) target_include_directories(ipopt INTERFACE ${Ipopt_INCLUDE_DIRS}) - if(${CMAKE_CXX_COMPILER_ID} STREQUAL "MSVC") - - else() + if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_definitions(ipopt INTERFACE HAVE_CSTDDEF) endif() target_compile_options(ipopt INTERFACE ${Ipopt_CFLAGS_OTHER}) From 1d28ef3a6fe3ed6993f273044e2a474165d15e21 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 16 Oct 2024 11:06:27 +0200 Subject: [PATCH 5/6] ipopt: Fix Ipopt module on Windows --- find-external/Ipopt/FindIpopt.cmake | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake index 2dd20a792..2af38f1f1 100644 --- a/find-external/Ipopt/FindIpopt.cmake +++ b/find-external/Ipopt/FindIpopt.cmake @@ -28,18 +28,29 @@ else() message(STATUS " Ipopt library dirs: ${Ipopt_LIBRARY_DIRS}") message(STATUS " Ipopt include dirs: ${Ipopt_INCLUDE_DIRS}") add_library(ipopt SHARED IMPORTED) + # On Windows, ipopt library is named ipopt-3 find_library( ipopt_lib_path - NAMES ipopt - PATHS ${Ipopt_LIBRARY_DIRS}) + NAMES ipopt ipopt-3 + PATHS ${Ipopt_LIBRARY_DIRS} REQUIRED) message(STATUS " Ipopt library found at ${ipopt_lib_path}") - set_target_properties(ipopt PROPERTIES IMPORTED_LOCATION ${ipopt_lib_path}) - target_include_directories(ipopt INTERFACE ${Ipopt_INCLUDE_DIRS}) + set_target_properties( + ipopt + PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${Ipopt_INCLUDE_DIRS}" + INTERFACE_COMPILE_OPTIONS "${Ipopt_CFLAGS_OTHER}" + IMPORTED_CONFIGURATIONS "RELEASE") if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") target_compile_definitions(ipopt INTERFACE HAVE_CSTDDEF) endif() - target_compile_options(ipopt INTERFACE ${Ipopt_CFLAGS_OTHER}) + + if(WIN32) + set_target_properties(ipopt PROPERTIES IMPORTED_IMPLIB_RELEASE + "${ipopt_lib_path}") + else() + set_target_properties(ipopt PROPERTIES IMPORTED_LOCATION_RELEASE + "${ipopt_lib_path}") + endif() add_library(Ipopt::Ipopt ALIAS ipopt) endif() From 9c3003c7f8fd9b23f56247507038bd941e1ffb60 Mon Sep 17 00:00:00 2001 From: Joris Vaillant Date: Wed, 16 Oct 2024 11:24:10 +0200 Subject: [PATCH 6/6] Ipopt: Remove an hack to manage bad debian packaging Since we don't know if this hack is still relevant, we remove it. Ref: https://github.com/ghorn/debian-coinor-ipopt/issues/2 --- find-external/Ipopt/FindIpopt.cmake | 4 ---- 1 file changed, 4 deletions(-) diff --git a/find-external/Ipopt/FindIpopt.cmake b/find-external/Ipopt/FindIpopt.cmake index 2af38f1f1..b85636115 100644 --- a/find-external/Ipopt/FindIpopt.cmake +++ b/find-external/Ipopt/FindIpopt.cmake @@ -40,10 +40,6 @@ else() INTERFACE_COMPILE_OPTIONS "${Ipopt_CFLAGS_OTHER}" IMPORTED_CONFIGURATIONS "RELEASE") - if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - target_compile_definitions(ipopt INTERFACE HAVE_CSTDDEF) - endif() - if(WIN32) set_target_properties(ipopt PROPERTIES IMPORTED_IMPLIB_RELEASE "${ipopt_lib_path}")