Skip to content

Commit

Permalink
[casadi] Add new port (#43425)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgillis authored Feb 11, 2025
1 parent b64c8e9 commit 6eba856
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ports/casadi/disable_fortran.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0200a56df..69b699626 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -84,23 +84,7 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type (default Release)" FORCE)
endif()

-########################################################################
-############################# Fortran ##################################
-########################################################################
-option(FORTRAN_REQUIRED "Make fortran a required dependency" OFF)
-
-# http://public.kitware.com/Bug/print_bug_page.php?bug_id=9220
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
-include(language_support)
-workaround_9220(Fortran Fortran_language_works)
-if(FORTRAN_REQUIRED)
- enable_language(Fortran)
- set(Fortran_language_works ON)
-else()
- if(Fortran_language_works)
- enable_language(Fortran OPTIONAL)
- endif()
-endif()

########################################################################
############################# C++11 ####################################
14 changes: 14 additions & 0 deletions ports/casadi/namespace.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96acbc2e5..f2a08c83d 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2167,7 +2167,7 @@ install(FILES

# Install the export set for use with the install-tree
file(RELATIVE_PATH REL_CMAKE_PREFIX "${CMAKE_INSTALL_PREFIX}" "${CMAKE_PREFIX}")
-install(EXPORT casadi-targets DESTINATION ${REL_CMAKE_PREFIX})
+install(EXPORT casadi-targets NAMESPACE casadi:: DESTINATION ${REL_CMAKE_PREFIX})

set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION_FULL})
diff --git a/docs/examples/cplusplus/cmake_find_package/CMakeLists.txt b/docs/examples/cplusplus/cmake_find_package/CMakeLists.txt
39 changes: 39 additions & 0 deletions ports/casadi/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Currently no upstream support for static libraries
vcpkg_check_linkage(ONLY_DYNAMIC_LIBRARY)

vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO casadi/casadi
REF "${VERSION}"
SHA512 2c95368281f0bda385c6c451e361c168589f13aa66af6bc6fadf01f899bcd6c785ea7da3dee0fb5835559e58982e499182a4d244af3ea208ac05f672ea99cfd1
HEAD_REF main
PATCHES relocatable.patch disable_fortran.patch namespace.cmake
)

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
-DWITH_SELFCONTAINED=OFF
-DWITH_TINYXML=OFF
-DWITH_BUILD_TINYXML=OFF
-DWITH_QPOASES=OFF
-DWITH_SUNDIALS=OFF
-DWITH_CSPARSE=OFF
-DLIB_PREFIX:PATH=lib
-DBIN_PREFIX:PATH=bin
-DINCLUDE_PREFIX:PATH=include
-DCMAKE_PREFIX:PATH=share/${PORT}
)

vcpkg_cmake_install()

vcpkg_cmake_config_fixup()

vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt")

vcpkg_fixup_pkgconfig()

configure_file("${CMAKE_CURRENT_LIST_DIR}/usage" "${CURRENT_PACKAGES_DIR}/share/${PORT}/usage" COPYONLY)

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_copy_tools(TOOL_NAMES casadi-cli AUTO_CLEAN)
47 changes: 47 additions & 0 deletions ports/casadi/relocatable.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b444c292e..0200a56df 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -297,6 +297,7 @@ option(ENABLE_STATIC "Compile static libraries (.a on Linux)" OFF)
option(ENABLE_SHARED "Compile shared libraries (.so on Linux)" ON)
option(SWIG_EXPORT "Export SWIG" OFF)
option(SWIG_IMPORT "Import SWIG" OFF)
+option(RELOCATABLE "Avoid any usage of absolute paths" ON)

# enabling OpenMP support if requested
option(WITH_OPENMP "Compile with parallelization support using OpenMP" OFF)
diff --git a/casadi/CMakeLists.txt b/casadi/CMakeLists.txt
index 3c803afc0..bd408fdd6 100644
--- a/casadi/CMakeLists.txt
+++ b/casadi/CMakeLists.txt
@@ -141,10 +141,16 @@ if(NOT SKIP_CONFIG_H_GENERATION)

# See issue #3831, RELOCATABILITY
set(CASADI_CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER})
- if(CASADI_CMAKE_CXX_COMPILER MATCHES "shims")
+ if(CASADI_CMAKE_CXX_COMPILER MATCHES "shims" OR RELOCATABLE)
get_filename_component(CASADI_CMAKE_CXX_COMPILER ${CMAKE_CXX_COMPILER} NAME)
endif()

+ if(RELOCATABLE)
+ set(CASADI_INSTALL_PREFIX "")
+ else()
+ set(CASADI_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
+ endif()
+
configure_file(config.h.cmake "${CMAKE_CURRENT_BINARY_DIR}/config.h" ESCAPE_QUOTES)
endif()
install(FILES casadi.hpp mem.h casadi_c.h "${CMAKE_CURRENT_BINARY_DIR}/config.h"
diff --git a/casadi/config.h.cmake b/casadi/config.h.cmake
index 2b805aede..3a4795eb2 100644
--- a/casadi/config.h.cmake
+++ b/casadi/config.h.cmake
@@ -38,7 +38,7 @@
#define CASADI_COMPILER_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${UPPER_CMAKE_BUILD_TYPE}} ${EXTRA_CXX_FLAGS_FROM_DEFS}" // NOLINT(whitespace/line_length)
#define CASADI_MODULES "${CASADI_MODULES}" // NOLINT(whitespace/line_length)
#define CASADI_PLUGINS "${CASADI_PLUGINS}" // NOLINT(whitespace/line_length)
-#define CASADI_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" // NOLINT(whitespace/line_length)
+#define CASADI_INSTALL_PREFIX "${CASADI_INSTALL_PREFIX}" // NOLINT(whitespace/line_length)
#define CASADI_SHARED_LIBRARY_PREFIX "${CMAKE_SHARED_LIBRARY_PREFIX}" // NOLINT(whitespace/line_length)
#define CASADI_SHARED_LIBRARY_SUFFIX "${CMAKE_SHARED_LIBRARY_SUFFIX}" // NOLINT(whitespace/line_length)
#define CASADI_OBJECT_FILE_SUFFIX "${CMAKE_C_OUTPUT_EXTENSION}" // NOLINT(whitespace/line_length)
4 changes: 4 additions & 0 deletions ports/casadi/usage
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
casadi provides CMake targets:

find_package(casadi CONFIG REQUIRED)
target_link_libraries(main PRIVATE casadi::casadi)
19 changes: 19 additions & 0 deletions ports/casadi/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "casadi",
"version": "3.6.7",
"port-version": 1,
"description": "CasADi is a symbolic framework for numeric optimization implementing automatic differentiation in forward and reverse modes on sparse matrix-valued computational graphs. It supports self-contained C-code generation and interfaces state-of-the-art codes such as SUNDIALS, IPOPT etc. It can be used from C++, Python or Matlab/Octave.",
"homepage": "https://web.casadi.org",
"license": "LGPL-3.0-only",
"supports": "!static & !uwp",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
4 changes: 4 additions & 0 deletions versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@
"baseline": "1.2.0",
"port-version": 0
},
"casadi": {
"baseline": "3.6.7",
"port-version": 1
},
"casclib": {
"baseline": "2024-06-05",
"port-version": 0
Expand Down
5 changes: 5 additions & 0 deletions versions/c-/casadi.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "41671a156bc091a5740da4900f0a4fcf7679c53b",
"version": "3.6.7",
"port-version": 1
},
{
"git-tree": "1adbc7383777c7c21ca1dea604f4a4c75780fe6e",
"version": "3.6.7",
Expand Down

0 comments on commit 6eba856

Please sign in to comment.