Skip to content

Commit

Permalink
feat: relocatable pkg-config files (minpack.pc)
Browse files Browse the repository at this point in the history
  • Loading branch information
luau-project committed Jun 2, 2024
1 parent 3d8f886 commit 272c429
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
27 changes: 27 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@
# Description: Installation directory for pkg-config (.pc) files. #
# Note: Must be a relative path to ${CMAKE_INSTALL_PREFIX}. #
# #
# RELOCATABLE_PKGCONFIG (type: BOOL, default value: ON) #
# Description: Enable the generated pkg-config file (minpack.pc) #
# to be relocatable. #
# Note: Must be a relative path to ${CMAKE_INSTALL_PREFIX}. #
# #
###############################################################################
# End(Description of parameters) #
###############################################################################
Expand All @@ -127,6 +132,7 @@ option(BUILD_SHARED_LIBS "Build the shared library." ON)
option(BUILD_STATIC_LIBS "Build the static library." OFF)
option(USE_DOWNLOAD "Download source code." ON)
set(DOWNLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Destination directory to store downloaded files.")
option(RELOCATABLE_PKGCONFIG "Enable the generated pkg-config file (minpack.pc) to be relocatable." ON)

# official minpack url
set(minpack_url "https://www.netlib.org/minpack")
Expand Down Expand Up @@ -298,6 +304,24 @@ set(minpack_intel_specific_Fflags_for_Unix "-assume" "underscore" "-names" "lowe
# hold targets to install
set(targets_to_install "")

if (RELOCATABLE_PKGCONFIG)

# eval number of parents directories
# between CMAKE_INSTALL_PREFIX and MINPACK_INSTALL_PKGCONFIGDIR
# to enable a relocatable pkg-config (.pc) file
set(__pcfiledir_suffix "")
set(__current_parent_dir "${CMAKE_INSTALL_PREFIX}/${MINPACK_INSTALL_PKGCONFIGDIR}")
while (NOT "${__current_parent_dir}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
get_filename_component(__current_parent_dir ${__current_parent_dir} PATH)
list(APPEND __pcfiledir_suffix "..")
endwhile()
list(JOIN __pcfiledir_suffix "/" __pcfiledir_joint_suffix)
set(MINPACK_PKGCONFIG_PREFIX "\${pcfiledir}/${__pcfiledir_joint_suffix}")

else()
set(MINPACK_PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif()

# Build the shared library
if (BUILD_SHARED_LIBS)
add_library(minpack_SHARED SHARED "")
Expand All @@ -322,6 +346,7 @@ if (BUILD_SHARED_LIBS)

set_target_properties(minpack_SHARED
PROPERTIES
Fortran_FORMAT FIXED
POSITION_INDEPENDENT_CODE ON
OUTPUT_NAME ${minpack_library_name}
)
Expand Down Expand Up @@ -354,6 +379,7 @@ if (BUILD_STATIC_LIBS)

set_target_properties(minpack_STATIC
PROPERTIES
Fortran_FORMAT FIXED
OUTPUT_NAME ${minpack_library_name}
)

Expand Down Expand Up @@ -410,6 +436,7 @@ message(STATUS "")
message(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}")
message(STATUS " Build shared libs ............... : ${BUILD_SHARED_LIBS}")
message(STATUS " Build static libs ............... : ${BUILD_STATIC_LIBS}")
message(STATUS " Relocatable pkg-config files .... : ${RELOCATABLE_PKGCONFIG}")
message(STATUS " ")
message(STATUS " Install directories:")
message(STATUS " ")
Expand Down
20 changes: 12 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ Build scripts for minpack.
* [What is minpack?](#what-is-minpack)
* [Why minpack-builder is needed?](#why-minpack-builder-is-needed)
* [How to solve the problem?](#how-to-solve-the-problem)
* [Documentation](#documentation)
* [Continuous Integration](#continuous-integration)
* [Windows 11](#windows-11)
* [Ubuntu 22.04](#ubuntu-2204)
* [Documentation](#documentation)
* [References](#references)

## Introduction
Expand All @@ -27,7 +27,7 @@ The primary goal of **minpack-builder** is to provide an unified C API and a sta
### What is minpack?

The original minpack [[1]](https://www.netlib.org/minpack) is a battle-tested **min**imization **pack**age written in Fortran 77 for solving a system of nonlinear equations and nonlinear least squares problems, discussed in details at [[3]](https://doi.org/10.2172/6997568). Throughout the years, popular scientific libraries like SciPy [[4]](https://github.com/scipy/scipy/tree/main/scipy/optimize/minpack) and Eigen [[5]](https://eigen.tuxfamily.org/dox/unsupported/index.html) have been using minpack to perform nonlinear optimization, either in unmodified form or rewritten to programming languages other than Fortran.
The original minpack [[1]](https://www.netlib.org/minpack) is a battle-tested **min**imization **pack**age written in Fortran 77 for solving a system of nonlinear equations and nonlinear least squares problems, discussed in details at [[3]](https://doi.org/10.2172/6997568). Throughout the years, popular scientific libraries like SciPy [[4]](https://github.com/scipy/scipy/tree/main/scipy/optimize/minpack) and Eigen [[5]](https://eigen.tuxfamily.org/dox/unsupported/index.html) have been using minpack to perform nonlinear optimization.

> [!IMPORTANT]
>
Expand All @@ -45,9 +45,17 @@ While MSYS2 is an excellent choice for people working with GCC-like toolchains,

In order to provide an unified C API for minpack, we use CMake [[2]](https://cmake.org/) as a build system to download the source code directly from the official minpack website [[1]](https://www.netlib.org/minpack). Then, we handle vendor-specific parameters of the Fortran compiler to build the library conforming to the API seen on Linux operating systems. Finally, we install it on a suitable location defined by the developer, making the minpack binaries easily discoverable as a CMake [[2]](https://cmake.org/) module or pkg-config [[15]](https://gitlab.freedesktop.org/pkg-config/pkg-config) module.

## Documentation

Browse the [documentation](doc/README.md).

## Continuous Integration

At the moment, the continuous integration on github is able to build and install minpack in the following combination of platform / compiler toolchain.
> [!TIP]
>
> The heavy testing of the capabilities of ```minpack-builder``` to build minpack happens on our project [https://github.com/luau-project/minpackex](https://github.com/luau-project/minpackex), which extends minpack API to allow an easier usage from C/C++. You definitely should check it out!
At the moment, the continuous integration on ```minpack-builder``` github is able to build and install minpack in the following combination of platform / compiler toolchain.

> [!NOTE]
>
Expand All @@ -57,7 +65,7 @@ At the moment, the continuous integration on github is able to build and install

| Fortran Compiler | Compiler Version | Build Status |
|------------------|------------------|--------------|
| GFortran | 13.2.0 | ![gfortran-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/gfortran-on-windows.yaml/badge.svg?branch=main) |
| GFortran | 14.1.0 | ![gfortran-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/gfortran-on-windows.yaml/badge.svg?branch=main) |
| Intel LLVM ifx (*MSVC-like*) | 2024.1.0 | ![ifx-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/intel-fortran-on-windows.yaml/badge.svg?branch=main) |
| LLVM Flang-new (*GCC-like*) | 18.1.4 | ![llvm-flang-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/llvm-flang-gcc-like-on-windows.yaml/badge.svg?branch=main) |

Expand All @@ -69,10 +77,6 @@ At the moment, the continuous integration on github is able to build and install
| Intel LLVM ifx (*GCC-like*) | 2024.1.0 | ![ifx-ubuntu workflow](https://github.com/luau-project/minpack-builder/actions/workflows/intel-fortran-on-ubuntu.yaml/badge.svg?branch=main) |
| LLVM Flang-new (*GCC-like*) | 18.1.3 |![llvm-flang-ubuntu workflow](https://github.com/luau-project/minpack-builder/actions/workflows/llvm-flang-on-ubuntu.yaml/badge.svg?branch=main)|

## Documentation

Browse the [documentation](doc/README.md).

## References

1. minpack. Accessed May 2, 2024. [https://www.netlib.org/minpack](https://www.netlib.org/minpack);
Expand Down
4 changes: 2 additions & 2 deletions cmake/minpack.pc.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
prefix=@MINPACK_PKGCONFIG_PREFIX@
exec_prefix=@MINPACK_PKGCONFIG_PREFIX@
lib_name=@minpack_library_name@
libdir=${exec_prefix}/@MINPACK_INSTALL_LIBDIR@
includedir=${prefix}/@MINPACK_INSTALL_INCLUDEDIR@
Expand Down
8 changes: 8 additions & 0 deletions doc/Configuration-Options.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [MINPACK_INSTALL_INCLUDEDIR](#MINPACK_INSTALL_INCLUDEDIR)
* [MINPACK_INSTALL_DOCDIR](#MINPACK_INSTALL_DOCDIR)
* [MINPACK_INSTALL_PKGCONFIGDIR](#MINPACK_INSTALL_PKGCONFIGDIR)
* [RELOCATABLE_PKGCONFIG](#RELOCATABLE_PKGCONFIG)

## CMAKE_BUILD_TYPE

Expand Down Expand Up @@ -107,5 +108,12 @@
* Default value: ${MINPACK_INSTALL_LIBDIR}/pkgconfig
* Note: This value must be a relative path to ${CMAKE_INSTALL_PREFIX}.

## RELOCATABLE_PKGCONFIG

* Parameter: RELOCATABLE_PKGCONFIG
* Description: Enable the generated pkg-config file (minpack.pc) to be relocatable.
* Type: BOOL
* Default value: ON.

---
[Documentation](README.md)

0 comments on commit 272c429

Please sign in to comment.