From c0b86d5981ff620d9b2b6f6509c19eccad0857e7 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Wed, 6 Jan 2021 23:10:59 +0100 Subject: [PATCH 1/3] Generate package file exports with CMake - set project version (just 0 as dummy) and project description in CMake - export CMake package fortran_lang-config.cmake for CMake projects - export pkg-config file fortran_lang.pc for non-CMake projects --- CMakeLists.txt | 9 ++++++++- README.md | 30 ++++++++++++++++++++++++++++++ config/CMakeLists.txt | 40 ++++++++++++++++++++++++++++++++++++++++ config/template.cmake | 5 +++++ config/template.pc | 9 +++++++++ 5 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 config/CMakeLists.txt create mode 100644 config/template.cmake create mode 100644 config/template.pc diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e69e4466..056e6bf48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,9 @@ cmake_minimum_required(VERSION 3.14.0) -project(fortran_stdlib Fortran) +project(fortran_stdlib + LANGUAGES Fortran + VERSION 0 + DESCRIPTION "Community driven and agreed upon de facto standard library for Fortran" +) enable_testing() # Follow GNU conventions for installation directories @@ -7,6 +11,9 @@ include(GNUInstallDirs) include(${PROJECT_SOURCE_DIR}/cmake/stdlib.cmake) +# --- CMake specific configuration and package data export +add_subdirectory(config) + # --- compiler options if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) add_compile_options(-fimplicit-none) diff --git a/README.md b/README.md index 94ff0d64a..d60e43469 100644 --- a/README.md +++ b/README.md @@ -158,6 +158,36 @@ make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4 ``` + +## Using stdlib in your project + +The stdlib projects exports CMake package files and pkg-config files to make stdlib usable for other projects. +The package files are located in the library directory in the installation prefix. + +For CMake builds of stdlib you can find a local installation with + +```cmake +find_package(fortran_stdlib REQUIRED) +... +target_link_libraries( + ${PROJECT_NAME} + PRIVATE + fortran_stdlib::fortran_stdlib +) +``` + +to make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. +The usual install localtion of the package files is ``$PREFIX/lib/cmake/fortran_stdlib``. + +For non-CMake build systems (like make) you can use the exported pkg-config file by setting ``PKG_CONFIG_PATH`` to include the directory containing the exported pc-file. +The usual install location of the pc-file is ``$PREFIX/lib/pkgconfig``. +In make you can obtain the required compile and link arguments with + +```make +STDLIB_CFLAGS := $(shell pkg-config --cflags fortran_stdlib) +STDLIB_LIBS := $(shell pkg-config --libs fortran_stdlib) +``` + ## Documentation Documentation is a work in progress (see issue [#4](https://github.com/fortran-lang/stdlib/issues/4)) but already available at [stdlib.fortran-lang.org](https://stdlib.fortran-lang.org). diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 000000000..c7ff1c83f --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,40 @@ +# SPDX-Identifier: MIT + +# Export a pkg-config file +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/template.pc" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + @ONLY +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig" +) + +# Export CMake package file +include(CMakePackageConfigHelpers) +configure_package_config_file( + "${CMAKE_CURRENT_SOURCE_DIR}/template.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) +if(BUILD_SHARED_LIBS) + # Due to the uncertain ABI compatibility of Fortran shared libraries + # limit compatibility for dynamic linking to same minor version. + set(COMPATIBILITY SameMinorVersion) +else() + # Require API compatibility via semantic versioning for static linking, + set(COMPATIBILITY SameMajorVersion) +endif() +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + VERSION "${PROJECT_VERSION}" + COMPATIBILITY ${COMPATIBILITY} +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) diff --git a/config/template.cmake b/config/template.cmake new file mode 100644 index 000000000..4746fe4d1 --- /dev/null +++ b/config/template.cmake @@ -0,0 +1,5 @@ +@PACKAGE_INIT@ + +if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@") + include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") +endif() diff --git a/config/template.pc b/config/template.pc new file mode 100644 index 000000000..35c137545 --- /dev/null +++ b/config/template.pc @@ -0,0 +1,9 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -l@PROJECT_NAME@ +Cflags: -I${includedir} From 26a1311e6bd0ba858222052b5e7534b096782f76 Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Fri, 8 Jan 2021 19:15:31 +0100 Subject: [PATCH 2/3] Account for prerelease version and different API compatibility --- config/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index c7ff1c83f..f6da8a2ac 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -19,12 +19,12 @@ configure_package_config_file( "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" ) -if(BUILD_SHARED_LIBS) +if(BUILD_SHARED_LIBS OR PROJECT_VERSION_MAJOR EQUAL 0) # Due to the uncertain ABI compatibility of Fortran shared libraries # limit compatibility for dynamic linking to same minor version. set(COMPATIBILITY SameMinorVersion) else() - # Require API compatibility via semantic versioning for static linking, + # Require API compatibility via semantic versioning for static linking. set(COMPATIBILITY SameMajorVersion) endif() write_basic_package_version_file( From 7ef70a0900d375383a7e81850892dda15b0b29cf Mon Sep 17 00:00:00 2001 From: Sebastian Ehlert <28669218+awvwgk@users.noreply.github.com> Date: Sun, 17 Jan 2021 17:41:11 +0100 Subject: [PATCH 3/3] Fix typos in README Co-authored-by: Jeremie Vandenplas --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d60e43469..088515266 100644 --- a/README.md +++ b/README.md @@ -161,7 +161,7 @@ make -f Makefile.manual FYPPFLAGS=-DMAXRANK=4 ## Using stdlib in your project -The stdlib projects exports CMake package files and pkg-config files to make stdlib usable for other projects. +The stdlib project exports CMake package files and pkg-config files to make stdlib usable for other projects. The package files are located in the library directory in the installation prefix. For CMake builds of stdlib you can find a local installation with @@ -176,7 +176,7 @@ target_link_libraries( ) ``` -to make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. +To make the installed stdlib project discoverable add the stdlib directory to the ``CMAKE_PREFIX_PATH``. The usual install localtion of the package files is ``$PREFIX/lib/cmake/fortran_stdlib``. For non-CMake build systems (like make) you can use the exported pkg-config file by setting ``PKG_CONFIG_PATH`` to include the directory containing the exported pc-file.