Skip to content
Snippets Groups Projects
Verified Commit 5195fb1d authored by Tim Kaune's avatar Tim Kaune
Browse files

Allow Debug builds but make Release the default

Refactor CMake presets to include the default install location
Update README accordingly
parent 9b540ee2
No related branches found
No related tags found
No related merge requests found
......@@ -2,3 +2,6 @@
!.gitignore
CMakeUserPresets.json
build/
install/
......@@ -42,16 +42,18 @@ if (DEFINED NetlibF2C_SHARED_LIBS)
set(BUILD_SHARED_LIBS "${NetlibF2C_SHARED_LIBS}")
endif ()
# NetlibF2C is a third-party tool and library, which we never want to debug
# NetlibF2C is a third-party tool and library, which we rarely want to debug.
# Set the default build type to Release.
# If using a multi config generator
get_property(_IS_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if (_IS_MULTI_CONFIG)
set(CMAKE_CONFIGURATION_TYPES "Release")
set(CMAKE_DEFAULT_BUILD_TYPE "Release")
# If using a single config generator
else ()
if (NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()
endif ()
if (BUILD_SHARED_LIBS)
include(CheckPIESupported)
......
......@@ -5,12 +5,15 @@
"minor": 25,
"patch": 0
},
"include": [
"CMakePresetsCommon.json"
],
"configurePresets": [
{
"name": "shared",
"hidden": true,
"cacheVariables": {
"NetlibF2C_SHARED_LIBS": "ON"
"NetlibF2C_SHARED_LIBS": true
},
"binaryDir": "${sourceDir}/build/shared"
},
......@@ -18,51 +21,191 @@
"name": "static",
"hidden": true,
"cacheVariables": {
"NetlibF2C_SHARED_LIBS": "OFF"
"NetlibF2C_SHARED_LIBS": false
},
"binaryDir": "${sourceDir}/build/static"
},
{
"name": "make",
"hidden": true,
"generator": "Unix Makefiles"
},
{
"name": "ninja",
"hidden": true,
"generator": "Ninja"
"name": "ninja-shared-release",
"inherits": [
"install",
"ninja",
"shared",
"release"
],
"binaryDir": "${sourceDir}/build/shared/release",
"displayName": "Shared Library Release Build Configuration using Ninja"
},
{
"name": "ninja-shared-release",
"name": "ninja-shared-debug",
"inherits": [
"install",
"ninja",
"shared",
"ninja"
"debug"
],
"displayName": "Shared Library Release Build using Ninja"
"binaryDir": "${sourceDir}/build/shared/debug",
"displayName": "Shared Library Debug Build Configuration using Ninja"
},
{
"name": "ninja-static-release",
"inherits": [
"install",
"ninja",
"static",
"ninja"
"release"
],
"displayName": "Static Library Release Build using Ninja"
"binaryDir": "${sourceDir}/build/static/release",
"displayName": "Static Library Release Build Configuration using Ninja"
},
{
"name": "ninja-static-debug",
"inherits": [
"install",
"ninja",
"static",
"debug"
],
"binaryDir": "${sourceDir}/build/static/debug",
"displayName": "Static Library Debug Build Configuration using Ninja"
},
{
"name": "ninja-multi-shared",
"inherits": [
"install",
"ninja-multi",
"shared"
],
"binaryDir": "${sourceDir}/build/shared/multi",
"displayName": "Shared Library Multi-Config using Ninja"
},
{
"name": "ninja-multi-static",
"inherits": [
"install",
"ninja-multi",
"static"
],
"binaryDir": "${sourceDir}/build/static/multi",
"displayName": "Static Library Multi-Config using Ninja"
},
{
"name": "make-shared-release",
"inherits": [
"install",
"make",
"shared",
"make"
"release"
],
"displayName": "Shared Library Release Build using Makefiles"
"binaryDir": "${sourceDir}/build/shared/release",
"displayName": "Shared Library Release Build Configuration using Makefiles"
},
{
"name": "make-shared-debug",
"inherits": [
"install",
"make",
"shared",
"debug"
],
"binaryDir": "${sourceDir}/build/shared/debug",
"displayName": "Shared Library Debug Build Configuration using Makefiles"
},
{
"name": "make-static-release",
"inherits": [
"install",
"make",
"static",
"release"
],
"binaryDir": "${sourceDir}/build/static/release",
"displayName": "Static Library Release Build Configuration using Makefiles"
},
{
"name": "make-static-debug",
"inherits": [
"install",
"make",
"static",
"make"
"debug"
],
"binaryDir": "${sourceDir}/build/static/debug",
"displayName": "Static Library Debug Build Configuration using Makefiles"
}
],
"displayName": "Static Library Release Build using Makefiles"
"buildPresets": [
{
"name": "ninja-shared-release",
"displayName": "Shared Library Release Build using Ninja",
"configurePreset": "ninja-shared-release"
},
{
"name": "ninja-shared-debug",
"displayName": "Shared Library Debug Build using Ninja",
"configurePreset": "ninja-shared-debug"
},
{
"name": "ninja-static-release",
"displayName": "Static Library Release Build using Ninja",
"configurePreset": "ninja-static-release"
},
{
"name": "ninja-static-debug",
"displayName": "Static Library Debug Build using Ninja",
"configurePreset": "ninja-static-debug"
},
{
"name": "ninja-multi-shared-release",
"inherits": [
"release"
],
"displayName": "Shared Library Release Build using Ninja",
"configurePreset": "ninja-multi-shared"
},
{
"name": "ninja-multi-shared-debug",
"inherits": [
"debug"
],
"displayName": "Shared Library Debug Build using Ninja",
"configurePreset": "ninja-multi-shared"
},
{
"name": "ninja-multi-static-release",
"inherits": [
"release"
],
"displayName": "Static Library Release Build using Ninja",
"configurePreset": "ninja-multi-static"
},
{
"name": "ninja-multi-static-debug",
"inherits": [
"debug"
],
"displayName": "Static Library Debug Build using Ninja",
"configurePreset": "ninja-multi-static"
},
{
"name": "make-shared-release",
"displayName": "Shared Library Release Build using Make",
"configurePreset": "make-shared-release"
},
{
"name": "make-shared-debug",
"displayName": "Shared Library Debug Build using Make",
"configurePreset": "make-shared-debug"
},
{
"name": "make-static-release",
"displayName": "Static Library Release Build using Make",
"configurePreset": "make-static-release"
},
{
"name": "make-static-debug",
"displayName": "Static Library Debug Build using Make",
"configurePreset": "make-static-debug"
}
]
}
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 25,
"patch": 0
},
"configurePresets": [
{
"name": "install",
"hidden": true,
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "./install"
}
},
{
"name": "release",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "debug",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "make",
"hidden": true,
"generator": "Unix Makefiles"
},
{
"name": "ninja",
"hidden": true,
"generator": "Ninja"
},
{
"name": "ninja-multi",
"hidden": true,
"generator": "Ninja Multi-Config"
}
],
"buildPresets": [
{
"name": "release",
"hidden": true,
"configuration": "Release"
},
{
"name": "debug",
"hidden": true,
"configuration": "Debug"
}
]
}
......@@ -32,17 +32,18 @@ What you need:
- [CMake](https://cmake.org/) and [Ninja](https://ninja-build.org/) for building
the project
- C compiler
- gcc for linux/mac (<https://gcc.gnu.org/>)
- cygwin + gcc for windows (<https://www.cygwin.com/>)
- GCC for Linux (<https://gcc.gnu.org/>)
- Clang for Mac OS X (<https://clang.llvm.org/>)
- Cygwin + GCC for Windows (<https://www.cygwin.com/>)
- LoadStaticSharedTargets (<https://gitlab.aei.uni-hannover.de/cmake/loadstaticsharedtargets>)
### Linux (Ubuntu) ###
Use your distribution's package manager to install the packages `cmake`, `ninja`
and `gcc`.
Use your distribution's package manager to install the packages `cmake`,
`ninja-build` and `gcc`.
```shell
$ sudo apt-get install cmake ninja gcc
$ sudo apt-get install cmake ninja-build gcc
```
### Mac OS X ###
......@@ -50,13 +51,13 @@ $ sudo apt-get install cmake ninja gcc
#### Homebrew ####
```shell
$ brew install cmake ninja gcc
$ brew install cmake ninja llvm
```
#### MacPorts ####
```shell
$ sudo port install cmake ninja gcc
$ sudo port install cmake ninja clang-devel
```
### Windows ###
......@@ -76,11 +77,12 @@ Install Cygwin and use the Cygwin package manager to install the packages
an arbitrary directory (e.g. `netlib-f2c`).
3. Go to this directory and type `cmake --list-presets`. A list of available
build configurations will be shown to you.
4. For building with `ninja`, type `cmake --preset ninja-shared-release`, if you
installed LoadStaticSharedTargets system-wide or not at all. Otherwise, type
4. For preparing a single configuration with `ninja`, type `cmake --preset
ninja-shared-release`, if you installed LoadStaticSharedTargets system-wide
or not at all. Otherwise, type
```shell
$ cmake -DCMAKE_PREFIX_PATH="/path/to/LoadStaticSharedTargets/install/prefix" --preset ninja-shared-release
$ cmake --preset ninja-shared-release -D "CMAKE_PREFIX_PATH=/path/to/LoadStaticSharedTargets/install/prefix"
```
Replace the path to the LoadStaticSharedTargets install prefix with the
......@@ -89,51 +91,74 @@ Install Cygwin and use the Cygwin package manager to install the packages
previous command:
```shell
$ cmake -DNetlibF2C_LICENSE_ACCEPTED=YES --preset ninja-shared-release
$ cmake --preset ninja-shared-release -D NetlibF2C_LICENSE_ACCEPTED=YES
```
or
This will populate the build directory with a CMake configuration tree. You
can also prepare all shared or static configurations at once by using `cmake
--preset ninja-multi-shared`. By default, the configured installation
directory is `./install`. You can specify a different install location by
setting the `CMAKE_INSTALL_PREFIX` variable:
```shell
$ cmake -DCMAKE_PREFIX_PATH="/path/to/LoadStaticSharedTargets/install/prefix" -DNetlibF2C_LICENSE_ACCEPTED=YES --preset ninja-shared-release
$ cmake --preset ninja-shared-release -D "CMAKE_INSTALL_PREFIX=/path/to/install/prefix"
```
This will populate the `build/shared` directory with a CMake build tree.
5. Now, you can build with `cmake --build ./build/shared`. You should see some
informative terminal output.
6. Finally, install the built artifacts to the `bin` folder with `cmake
--install ./build/shared --prefix ./bin`. You can also specify a different
install prefix, e. g. if you want to install system-wide: `cmake --install
./build/shared --prefix /usr/local` (might require `sudo`). You can also
install either only the executable or only the library with `cmake --install
./build/shared --prefix <any> --component executable` or `cmake --install
./build/shared --prefix <any> --component library`.
7. Repeat steps 4. - 6. with `cmake --preset ninja-static-release` and the build
directory `./build/static`.
The `-D` option can be given multiple times, so you can combine
`CMAKE_PREFIX_PATH`, `NetlibF2C_LICENSE_ACCEPTED` and `CMAKE_INSTALL_PREFIX`.
5. Now, you can build with `cmake --build --preset ninja-shared-release`. You
should see some informative terminal output. If you used a Ninja Multi-Config
in the previous step, you have to determine the config to build now: `cmake
--build --preset ninja-multi-shared-release` (repeat with the debug config).
See all available build presets with `cmake --build --list-presets`.
6. Finally, install the built artifacts to the configured install prefix with
`cmake --build --preset ninja-shared-release --target install`. If the
configured install prefix is a system-wide location (like `/usr/local`),
installing might require `sudo`. If you used a Ninja Multi-Config in step 4,
use the respective build preset for installing, too: `cmake --build --preset
ninja-multi-shared-release --target install` (repeat with the debug config).
You can also install either only the executable or only the library with
`cmake --build --preset ninja-shared-release --target install --component
executable` or `cmake --build --preset ninja-shared-release --target install
--component library`.
7. Repeat this process for the single config presets `ninja-static-release`,
`ninja-shared-debug` and `ninja-static-debug` or for the other multi-config
preset.
Now, the `f2c` code is compiled and you can use it in other projects. The
installed `f2c` package is discoverable by CMake as __NetlibF2C__. In the
`CMakeLists.txt` of the other project, call:
```cmake
find_package(NetlibF2C CONFIG REQUIRED)
include(FetchContent)
FetchContent_Declare(
NetlibF2C
GIT_REPOSITORY "git@gitlab.aei.uni-hannover.de:netlib/netlib-f2c.git"
GIT_TAG v1.5.0
SYSTEM
FIND_PACKAGE_ARGS 1.5.0 CONFIG NAMES NetlibF2C
)
set(NetlibF2C_INCLUDE_PACKAGING TRUE)
FetchContent_MakeAvailable(NetlibF2C)
```
This makes two CMake targets available to you, the `Netlib::f2c` executable
target and the `Netlib::libf2c` library target (static or shared depends on the
value of `BUILD_SHARED_LIBS` in the other project).
Then, to help CMake discover the NetlibF2C package, call CMake for the other
project like this:
This discovers an installed version of the NetlibF2C package or adds it to the
other project's install targets. To help CMake discover the NetlibF2C package,
call CMake for the other project like this:
```shell
$ cmake -B ./build -DCMAKE_PREFIX_PATH="/path/to/NetlibF2C/install/prefix"
$ cmake -B ./build -D "CMAKE_PREFIX_PATH=/path/to/NetlibF2C/install/prefix"
```
Replace the path to the NetlibF2C install prefix with the actual path on your
system! If NetlibF2C is installed in a proper system-wide location, the
`CMAKE_PREFIX_PATH` shouldn't be necessary.
This makes two CMake targets available to you, the `Netlib::f2c` executable
target and the `Netlib::libf2c` library target (static or shared depends on the
value of `BUILD_SHARED_LIBS` in the other project).
For more information read the `f2c` executable's man page.
## References ##
......
*
!.gitignore
*
!.gitignore
......@@ -21,5 +21,12 @@ find_program(DIFF_EXE diff)
find_program(PATCH_EXE patch REQUIRED)
find_program(ED_EXE ed REQUIRED)
if (BUILD_SHARED_LIBS)
set(F2C_DEBUG_POSTFIX "-debug")
else ()
set(F2C_RELEASE_POSTFIX "_static")
set(F2C_DEBUG_POSTFIX "_static-debug")
endif ()
add_subdirectory(f2c)
add_subdirectory(libf2c)
......@@ -275,12 +275,13 @@ else ()
PRIVATE
$<$<NOT:$<PLATFORM_ID:Darwin>>:-static>
)
endif ()
set_target_properties(
f2c
PROPERTIES
RELEASE_POSTFIX "_static"
DEBUG_POSTFIX "_static"
RELEASE_POSTFIX "${F2C_RELEASE_POSTFIX}"
DEBUG_POSTFIX "${F2C_DEBUG_POSTFIX}"
)
endif ()
target_include_directories(f2c PRIVATE "${F2C_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}")
......@@ -662,10 +662,6 @@ list(FILTER LIBF2C_OBJECTS_PARTIAL_WITHOUT_MAIN EXCLUDE REGEX [=[main\.c\.o$]=])
set(LIBF2C_OBJECTS_PARTIAL_ONLY_MAIN ${LIBF2C_OBJECTS_PARTIAL})
list(FILTER LIBF2C_OBJECTS_PARTIAL_ONLY_MAIN INCLUDE REGEX [=[main\.c\.o$]=])
if (NOT BUILD_SHARED_LIBS)
set(LIBF2C_POSTFIX "_static")
endif ()
add_library(libf2c)
add_library(Netlib::libf2c ALIAS libf2c)
......@@ -674,8 +670,8 @@ set_target_properties(
OUTPUT_NAME f2c
VERSION ${NetlibF2C_VERSION}
SOVERSION ${NetlibF2C_VERSION_MAJOR}
RELEASE_POSTFIX "${LIBF2C_POSTFIX}"
DEBUG_POSTFIX "${LIBF2C_POSTFIX}"
RELEASE_POSTFIX "${F2C_RELEASE_POSTFIX}"
DEBUG_POSTFIX "${F2C_DEBUG_POSTFIX}"
)
target_sources(libf2c PRIVATE
......@@ -707,8 +703,8 @@ set_target_properties(
OUTPUT_NAME f2cWithFortranMain
VERSION ${NetlibF2C_VERSION}
SOVERSION ${NetlibF2C_VERSION_MAJOR}
RELEASE_POSTFIX "${LIBF2C_POSTFIX}"
DEBUG_POSTFIX "${LIBF2C_POSTFIX}"
RELEASE_POSTFIX "${F2C_RELEASE_POSTFIX}"
DEBUG_POSTFIX "${F2C_DEBUG_POSTFIX}"
LINKER_LANGUAGE C
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment