Skip to content

Commit 272c429

Browse files
committed
feat: relocatable pkg-config files (minpack.pc)
1 parent 3d8f886 commit 272c429

File tree

4 files changed

+49
-10
lines changed

4 files changed

+49
-10
lines changed

CMakeLists.txt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@
107107
# Description: Installation directory for pkg-config (.pc) files. #
108108
# Note: Must be a relative path to ${CMAKE_INSTALL_PREFIX}. #
109109
# #
110+
# RELOCATABLE_PKGCONFIG (type: BOOL, default value: ON) #
111+
# Description: Enable the generated pkg-config file (minpack.pc) #
112+
# to be relocatable. #
113+
# Note: Must be a relative path to ${CMAKE_INSTALL_PREFIX}. #
114+
# #
110115
###############################################################################
111116
# End(Description of parameters) #
112117
###############################################################################
@@ -127,6 +132,7 @@ option(BUILD_SHARED_LIBS "Build the shared library." ON)
127132
option(BUILD_STATIC_LIBS "Build the static library." OFF)
128133
option(USE_DOWNLOAD "Download source code." ON)
129134
set(DOWNLOAD_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE PATH "Destination directory to store downloaded files.")
135+
option(RELOCATABLE_PKGCONFIG "Enable the generated pkg-config file (minpack.pc) to be relocatable." ON)
130136

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

307+
if (RELOCATABLE_PKGCONFIG)
308+
309+
# eval number of parents directories
310+
# between CMAKE_INSTALL_PREFIX and MINPACK_INSTALL_PKGCONFIGDIR
311+
# to enable a relocatable pkg-config (.pc) file
312+
set(__pcfiledir_suffix "")
313+
set(__current_parent_dir "${CMAKE_INSTALL_PREFIX}/${MINPACK_INSTALL_PKGCONFIGDIR}")
314+
while (NOT "${__current_parent_dir}" STREQUAL "${CMAKE_INSTALL_PREFIX}")
315+
get_filename_component(__current_parent_dir ${__current_parent_dir} PATH)
316+
list(APPEND __pcfiledir_suffix "..")
317+
endwhile()
318+
list(JOIN __pcfiledir_suffix "/" __pcfiledir_joint_suffix)
319+
set(MINPACK_PKGCONFIG_PREFIX "\${pcfiledir}/${__pcfiledir_joint_suffix}")
320+
321+
else()
322+
set(MINPACK_PKGCONFIG_PREFIX "${CMAKE_INSTALL_PREFIX}")
323+
endif()
324+
301325
# Build the shared library
302326
if (BUILD_SHARED_LIBS)
303327
add_library(minpack_SHARED SHARED "")
@@ -322,6 +346,7 @@ if (BUILD_SHARED_LIBS)
322346

323347
set_target_properties(minpack_SHARED
324348
PROPERTIES
349+
Fortran_FORMAT FIXED
325350
POSITION_INDEPENDENT_CODE ON
326351
OUTPUT_NAME ${minpack_library_name}
327352
)
@@ -354,6 +379,7 @@ if (BUILD_STATIC_LIBS)
354379

355380
set_target_properties(minpack_STATIC
356381
PROPERTIES
382+
Fortran_FORMAT FIXED
357383
OUTPUT_NAME ${minpack_library_name}
358384
)
359385

@@ -410,6 +436,7 @@ message(STATUS "")
410436
message(STATUS " Build type ...................... : ${CMAKE_BUILD_TYPE}")
411437
message(STATUS " Build shared libs ............... : ${BUILD_SHARED_LIBS}")
412438
message(STATUS " Build static libs ............... : ${BUILD_STATIC_LIBS}")
439+
message(STATUS " Relocatable pkg-config files .... : ${RELOCATABLE_PKGCONFIG}")
413440
message(STATUS " ")
414441
message(STATUS " Install directories:")
415442
message(STATUS " ")

README.md

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ Build scripts for minpack.
99
* [What is minpack?](#what-is-minpack)
1010
* [Why minpack-builder is needed?](#why-minpack-builder-is-needed)
1111
* [How to solve the problem?](#how-to-solve-the-problem)
12+
* [Documentation](#documentation)
1213
* [Continuous Integration](#continuous-integration)
1314
* [Windows 11](#windows-11)
1415
* [Ubuntu 22.04](#ubuntu-2204)
15-
* [Documentation](#documentation)
1616
* [References](#references)
1717

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

30-
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.
30+
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.
3131

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

4646
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.
4747

48+
## Documentation
49+
50+
Browse the [documentation](doc/README.md).
51+
4852
## Continuous Integration
4953

50-
At the moment, the continuous integration on github is able to build and install minpack in the following combination of platform / compiler toolchain.
54+
> [!TIP]
55+
>
56+
> 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!
57+
58+
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.
5159

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

5866
| Fortran Compiler | Compiler Version | Build Status |
5967
|------------------|------------------|--------------|
60-
| GFortran | 13.2.0 | ![gfortran-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/gfortran-on-windows.yaml/badge.svg?branch=main) |
68+
| GFortran | 14.1.0 | ![gfortran-win workflow](https://github.com/luau-project/minpack-builder/actions/workflows/gfortran-on-windows.yaml/badge.svg?branch=main) |
6169
| 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) |
6270
| 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) |
6371

@@ -69,10 +77,6 @@ At the moment, the continuous integration on github is able to build and install
6977
| 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) |
7078
| 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)|
7179

72-
## Documentation
73-
74-
Browse the [documentation](doc/README.md).
75-
7680
## References
7781

7882
1. minpack. Accessed May 2, 2024. [https://www.netlib.org/minpack](https://www.netlib.org/minpack);

cmake/minpack.pc.in

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
prefix=@CMAKE_INSTALL_PREFIX@
2-
exec_prefix=@CMAKE_INSTALL_PREFIX@
1+
prefix=@MINPACK_PKGCONFIG_PREFIX@
2+
exec_prefix=@MINPACK_PKGCONFIG_PREFIX@
33
lib_name=@minpack_library_name@
44
libdir=${exec_prefix}/@MINPACK_INSTALL_LIBDIR@
55
includedir=${prefix}/@MINPACK_INSTALL_INCLUDEDIR@

doc/Configuration-Options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [MINPACK_INSTALL_INCLUDEDIR](#MINPACK_INSTALL_INCLUDEDIR)
1919
* [MINPACK_INSTALL_DOCDIR](#MINPACK_INSTALL_DOCDIR)
2020
* [MINPACK_INSTALL_PKGCONFIGDIR](#MINPACK_INSTALL_PKGCONFIGDIR)
21+
* [RELOCATABLE_PKGCONFIG](#RELOCATABLE_PKGCONFIG)
2122

2223
## CMAKE_BUILD_TYPE
2324

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

111+
## RELOCATABLE_PKGCONFIG
112+
113+
* Parameter: RELOCATABLE_PKGCONFIG
114+
* Description: Enable the generated pkg-config file (minpack.pc) to be relocatable.
115+
* Type: BOOL
116+
* Default value: ON.
117+
110118
---
111119
[Documentation](README.md)

0 commit comments

Comments
 (0)