From 0d7c5de059413072d4de47903bf56c0a69d6613b Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 16:45:52 +0200 Subject: [PATCH 1/8] Addition of CMakefiles based on stdlib implementation --- CMakeLists.txt | 75 ++++++++++++++++++++++++++++++++++++ cmake/minpack.cmake | 49 ++++++++++++++++++++++++ config/CMakeLists.txt | 80 +++++++++++++++++++++++++++++++++++++++ config/DefaultFlags.cmake | 50 ++++++++++++++++++++++++ config/template.cmake | 9 +++++ config/template.pc | 10 +++++ examples/CMakeLists.txt | 19 ++++++++++ src/CMakeLists.txt | 44 +++++++++++++++++++++ test/CMakeLists.txt | 22 +++++++++++ 9 files changed, 358 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/minpack.cmake create mode 100644 config/CMakeLists.txt create mode 100644 config/DefaultFlags.cmake create mode 100644 config/template.cmake create mode 100644 config/template.pc create mode 100644 examples/CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 test/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..703d564 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,75 @@ +cmake_minimum_required(VERSION 3.14.0) + +# Include overwrites before setting up the project +set(CMAKE_USER_MAKE_RULES_OVERRIDE ${CMAKE_CURRENT_SOURCE_DIR}/config/DefaultFlags.cmake) + +project(minpack + LANGUAGES Fortran + VERSION "2.0.0" + DESCRIPTION "Minpack includes software for solving nonlinear equations and nonlinear least squares problems" +) + +include(CTest) + +# Follow GNU conventions for installation directories +include(GNUInstallDirs) + +include(${PROJECT_SOURCE_DIR}/cmake/minpack.cmake) + +# --- CMake specific configuration and package data export +add_subdirectory(config) + +# --- compiler selection +if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) + message(FATAL_ERROR "GCC Version 9 or newer required") +endif() + +# --- compiler feature checks +include(CheckFortranSourceCompiles) +include(CheckFortranSourceRuns) +check_fortran_source_runs("i=0; error stop i; end" f18errorstop) +check_fortran_source_compiles("real, allocatable :: array(:, :, :, :, :, :, :, :, :, :); end" f03rank SRC_EXT f90) +check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128) + +if(NOT DEFINED CMAKE_MAXIMUM_RANK) + set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures") +endif() + +# --- find preprocessor +find_program(FYPP fypp) +if(NOT FYPP) + message(FATAL_ERROR "Preprocessor fypp not found! Please install fypp following the instructions in https://fypp.readthedocs.io/en/stable/fypp.html#installing") +endif() + +# Custom preprocessor flags +if(DEFINED CMAKE_MAXIMUM_RANK) + set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") +elseif(f03rank) + set(fyppFlags) +else() + set(fyppFlags "-DVERSION90") +endif() + +list( + APPEND fyppFlags + "-DWITH_CBOOL=$" + "-DWITH_QP=$" + "-DWITH_XDP=$" + "-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}" + "-DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}" + "-DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}" + "-I${PROJECT_SOURCE_DIR}/include" +) + +add_subdirectory(src) + +if(BUILD_TESTING) + enable_testing() + add_subdirectory(test) + add_subdirectory(examples) +endif() + +install(EXPORT ${PROJECT_NAME}-targets + NAMESPACE ${PROJECT_NAME}:: + DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}" +) diff --git a/cmake/minpack.cmake b/cmake/minpack.cmake new file mode 100644 index 0000000..bdaf87d --- /dev/null +++ b/cmake/minpack.cmake @@ -0,0 +1,49 @@ +# Preprocesses a list of files with given preprocessor and preprocessor options +# +# Args: +# preproc [in]: Preprocessor program +# preprocopts [in]: Preprocessor options +# srcext [in]: File extension of the source files +# trgext [in]: File extension of the target files +# srcfiles [in]: List of the source files +# trgfiles [out]: Contains the list of the preprocessed files on exit +# +function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles) + + set(_trgfiles) + foreach(srcfile IN LISTS srcfiles) + string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile}) + add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} + COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} + MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}) + list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}) + endforeach() + set(${trgfiles} ${_trgfiles} PARENT_SCOPE) + +endfunction() + + + +# Preprocesses fortran files with fypp. +# +# It assumes that source files have the ".fypp" extension. Target files will be +# created with the extension ".f90". The FYPP variable must contain the path to +# the fypp-preprocessor. +# +# Args: +# fyppopts [in]: Options to pass to fypp. +# fyppfiles [in]: Files to be processed by fypp +# f90files [out]: List of created f90 files on exit +# +function (fypp_f90 fyppopts fyppfiles f90files) + preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files) + set(${f90files} ${_f90files} PARENT_SCOPE) +endfunction() + +# For fortran sources that contain C preprocessor flags: create ".F90" files +function (fypp_f90pp fyppopts fyppfiles F90files) + preprocess("${FYPP}" "${fyppopts}" "fypp" "F90" "${fyppfiles}" _F90files) + set(${F90files} ${_F90files} PARENT_SCOPE) +endfunction() + diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt new file mode 100644 index 0000000..10025c3 --- /dev/null +++ b/config/CMakeLists.txt @@ -0,0 +1,80 @@ +# SPDX-Identifier: MIT + +if(NOT DEFINED CMAKE_INSTALL_MODULEDIR) + set( + CMAKE_INSTALL_MODULEDIR + "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}/${CMAKE_Fortran_COMPILER_ID}-${CMAKE_Fortran_COMPILER_VERSION}" + CACHE + STRING + "Directory in prefix to install generated module files" + ) +endif() + +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") +set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) + +# Check for available features +# Note: users can overwrite the automatic check by setting the value at configure time +include(CheckFortranSourceRuns) +if (NOT DEFINED WITH_CBOOL) + check_fortran_source_runs( + "use, intrinsic :: iso_c_binding, only: c_bool; integer, parameter :: lk = kind(.true.) + if (c_bool == lk) stop 1 + end" + WITH_CBOOL + ) + set(WITH_CBOOL ${WITH_CBOOL} PARENT_SCOPE) +endif() +if (NOT DEFINED WITH_QP) + check_fortran_source_runs( + "if (selected_real_kind(33) == -1) stop 1; end" + WITH_QP + ) + set(WITH_QP ${WITH_QP} PARENT_SCOPE) +endif() +if (NOT DEFINED WITH_XDP) + check_fortran_source_runs( + "if (any(selected_real_kind(18) == [-1, selected_real_kind(33)])) stop 1; end" + WITH_XDP + ) + set(WITH_XDP ${WITH_XDP} PARENT_SCOPE) +endif() + +# 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 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. + 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/DefaultFlags.cmake b/config/DefaultFlags.cmake new file mode 100644 index 0000000..eafe7a4 --- /dev/null +++ b/config/DefaultFlags.cmake @@ -0,0 +1,50 @@ +if(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") + set( + CMAKE_Fortran_FLAGS_INIT + "-fimplicit-none" + "-ffree-line-length-132" + ) + set( + CMAKE_Fortran_FLAGS_RELEASE_INIT + ) + set( + CMAKE_Fortran_FLAGS_DEBUG_INIT + "-Wall" + "-Wextra" + "-Wimplicit-procedure" + "-std=f2018" + ) +elseif(CMAKE_Fortran_COMPILER_ID MATCHES "^Intel") + set( + CMAKE_Fortran_FLAGS_INIT + ) + set( + CMAKE_Fortran_FLAGS_RELEASE_INIT + ) + if(WIN32) + set( + CMAKE_Fortran_FLAGS_DEBUG_INIT + "/stand:f18" + "/warn:declarations,general,usage,interfaces,unused" + ) + else() + set( + CMAKE_Fortran_FLAGS_DEBUG_INIT + "-stand f18" + "-warn declarations,general,usage,interfaces,unused" + ) + endif() +else() + set( + CMAKE_Fortran_FLAGS_INIT + ) + set( + CMAKE_Fortran_FLAGS_RELEASE_INIT + ) + set( + CMAKE_Fortran_FLAGS_DEBUG_INIT + ) +endif() +string(REPLACE ";" " " CMAKE_Fortran_FLAGS_INIT "${CMAKE_Fortran_FLAGS_INIT}") +string(REPLACE ";" " " CMAKE_Fortran_FLAGS_RELEASE_INIT "${CMAKE_Fortran_FLAGS_RELEASE_INIT}") +string(REPLACE ";" " " CMAKE_Fortran_FLAGS_DEBUG_INIT "${CMAKE_Fortran_FLAGS_DEBUG_INIT}") diff --git a/config/template.cmake b/config/template.cmake new file mode 100644 index 0000000..9a0b15e --- /dev/null +++ b/config/template.cmake @@ -0,0 +1,9 @@ +@PACKAGE_INIT@ + +set("@PROJECT_NAME@_WITH_CBOOL" @WITH_CBOOL@) +set("@PROJECT_NAME@_WITH_QP" @WITH_QP@) +set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@) + +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 0000000..eecdda9 --- /dev/null +++ b/config/template.pc @@ -0,0 +1,10 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ +moduledir=${prefix}/@CMAKE_INSTALL_MODULEDIR@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +Version: @PROJECT_VERSION@ +Libs: -L${libdir} -l@PROJECT_NAME@ +Cflags: -I${includedir} -I${moduledir} diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..8123001 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,19 @@ +macro(ADDEXAMPLE name) + add_executable(example_${name} example_${name}.f90) + target_link_libraries(example_${name} "${PROJECT_NAME}") + add_test(NAME ${name} + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endmacro(ADDEXAMPLE) + +set(examples + "hybrd" + "hybrd1" + "lmder1" + "lmdif1" + "primes" +) + +foreach(example IN LISTS examples) + ADDEXAMPLE(${example}) +endforeach() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..6a12a1a --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,44 @@ +set(SRC + minpack.f90 + minpack_capi.f90 +) + +add_library(${PROJECT_NAME} ${SRC}) + +set_target_properties( + ${PROJECT_NAME} + PROPERTIES + POSITION_INDEPENDENT_CODE ON + WINDOWS_EXPORT_ALL_SYMBOLS ON +) + +if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 10.0) + target_compile_options( + ${PROJECT_NAME} + PRIVATE + $<$:-fno-range-check> + ) +endif() + +set(LIB_MOD_DIR ${CMAKE_CURRENT_BINARY_DIR}/mod_files/) +# We need the module directory before we finish the configure stage since the +# build interface might resolve before the module directory is generated by CMake +if(NOT EXISTS "${LIB_MOD_DIR}") + make_directory("${LIB_MOD_DIR}") +endif() + +set_target_properties(${PROJECT_NAME} PROPERTIES + Fortran_MODULE_DIRECTORY ${LIB_MOD_DIR}) + +target_include_directories(${PROJECT_NAME} PUBLIC + $ + $ +) + +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}-targets + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" + ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +install(DIRECTORY ${LIB_MOD_DIR} DESTINATION "${CMAKE_INSTALL_MODULEDIR}") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..435f31f --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,22 @@ +macro(ADDTEST name) + add_executable(test_${name} test_${name}.f90) + target_link_libraries(test_${name} "${PROJECT_NAME}") + add_test(NAME ${name} + COMMAND $ ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) +endmacro(ADDTEST) + +set(tests + "chkder" + "hybrd" + "hybrj" + "lmder" + "lmdif" + "lmstr" +) + +foreach(test IN LISTS tests) + ADDTEST(${test}) +endforeach() + + From 42fe6bfd7b51ee961254ac0b347576ca1d433f45 Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 16:54:46 +0200 Subject: [PATCH 2/8] Clean CMake files --- CMakeLists.txt | 40 ----------------------------------- cmake/minpack.cmake | 49 ------------------------------------------- config/CMakeLists.txt | 27 ------------------------ config/template.cmake | 4 ---- 4 files changed, 120 deletions(-) delete mode 100644 cmake/minpack.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 703d564..5edcbe4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,52 +14,12 @@ include(CTest) # Follow GNU conventions for installation directories include(GNUInstallDirs) -include(${PROJECT_SOURCE_DIR}/cmake/minpack.cmake) - # --- CMake specific configuration and package data export add_subdirectory(config) -# --- compiler selection -if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU AND CMAKE_Fortran_COMPILER_VERSION VERSION_LESS 9.0) - message(FATAL_ERROR "GCC Version 9 or newer required") -endif() - # --- compiler feature checks include(CheckFortranSourceCompiles) include(CheckFortranSourceRuns) -check_fortran_source_runs("i=0; error stop i; end" f18errorstop) -check_fortran_source_compiles("real, allocatable :: array(:, :, :, :, :, :, :, :, :, :); end" f03rank SRC_EXT f90) -check_fortran_source_runs("use, intrinsic :: iso_fortran_env, only : real128; real(real128) :: x; x = x+1; end" f03real128) - -if(NOT DEFINED CMAKE_MAXIMUM_RANK) - set(CMAKE_MAXIMUM_RANK 4 CACHE STRING "Maximum array rank for generated procedures") -endif() - -# --- find preprocessor -find_program(FYPP fypp) -if(NOT FYPP) - message(FATAL_ERROR "Preprocessor fypp not found! Please install fypp following the instructions in https://fypp.readthedocs.io/en/stable/fypp.html#installing") -endif() - -# Custom preprocessor flags -if(DEFINED CMAKE_MAXIMUM_RANK) - set(fyppFlags "-DMAXRANK=${CMAKE_MAXIMUM_RANK}") -elseif(f03rank) - set(fyppFlags) -else() - set(fyppFlags "-DVERSION90") -endif() - -list( - APPEND fyppFlags - "-DWITH_CBOOL=$" - "-DWITH_QP=$" - "-DWITH_XDP=$" - "-DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}" - "-DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}" - "-DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}" - "-I${PROJECT_SOURCE_DIR}/include" -) add_subdirectory(src) diff --git a/cmake/minpack.cmake b/cmake/minpack.cmake deleted file mode 100644 index bdaf87d..0000000 --- a/cmake/minpack.cmake +++ /dev/null @@ -1,49 +0,0 @@ -# Preprocesses a list of files with given preprocessor and preprocessor options -# -# Args: -# preproc [in]: Preprocessor program -# preprocopts [in]: Preprocessor options -# srcext [in]: File extension of the source files -# trgext [in]: File extension of the target files -# srcfiles [in]: List of the source files -# trgfiles [out]: Contains the list of the preprocessed files on exit -# -function(preprocess preproc preprocopts srcext trgext srcfiles trgfiles) - - set(_trgfiles) - foreach(srcfile IN LISTS srcfiles) - string(REGEX REPLACE "\\.${srcext}$" ".${trgext}" trgfile ${srcfile}) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} - COMMAND ${preproc} ${preprocopts} ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile} ${CMAKE_CURRENT_BINARY_DIR}/${trgfile} - MAIN_DEPENDENCY ${CMAKE_CURRENT_SOURCE_DIR}/${srcfile}) - list(APPEND _trgfiles ${CMAKE_CURRENT_BINARY_DIR}/${trgfile}) - endforeach() - set(${trgfiles} ${_trgfiles} PARENT_SCOPE) - -endfunction() - - - -# Preprocesses fortran files with fypp. -# -# It assumes that source files have the ".fypp" extension. Target files will be -# created with the extension ".f90". The FYPP variable must contain the path to -# the fypp-preprocessor. -# -# Args: -# fyppopts [in]: Options to pass to fypp. -# fyppfiles [in]: Files to be processed by fypp -# f90files [out]: List of created f90 files on exit -# -function (fypp_f90 fyppopts fyppfiles f90files) - preprocess("${FYPP}" "${fyppopts}" "fypp" "f90" "${fyppfiles}" _f90files) - set(${f90files} ${_f90files} PARENT_SCOPE) -endfunction() - -# For fortran sources that contain C preprocessor flags: create ".F90" files -function (fypp_f90pp fyppopts fyppfiles F90files) - preprocess("${FYPP}" "${fyppopts}" "fypp" "F90" "${fyppfiles}" _F90files) - set(${F90files} ${_F90files} PARENT_SCOPE) -endfunction() - diff --git a/config/CMakeLists.txt b/config/CMakeLists.txt index 10025c3..f215d39 100644 --- a/config/CMakeLists.txt +++ b/config/CMakeLists.txt @@ -13,33 +13,6 @@ endif() list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE) -# Check for available features -# Note: users can overwrite the automatic check by setting the value at configure time -include(CheckFortranSourceRuns) -if (NOT DEFINED WITH_CBOOL) - check_fortran_source_runs( - "use, intrinsic :: iso_c_binding, only: c_bool; integer, parameter :: lk = kind(.true.) - if (c_bool == lk) stop 1 - end" - WITH_CBOOL - ) - set(WITH_CBOOL ${WITH_CBOOL} PARENT_SCOPE) -endif() -if (NOT DEFINED WITH_QP) - check_fortran_source_runs( - "if (selected_real_kind(33) == -1) stop 1; end" - WITH_QP - ) - set(WITH_QP ${WITH_QP} PARENT_SCOPE) -endif() -if (NOT DEFINED WITH_XDP) - check_fortran_source_runs( - "if (any(selected_real_kind(18) == [-1, selected_real_kind(33)])) stop 1; end" - WITH_XDP - ) - set(WITH_XDP ${WITH_XDP} PARENT_SCOPE) -endif() - # Export a pkg-config file configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/template.pc" diff --git a/config/template.cmake b/config/template.cmake index 9a0b15e..4746fe4 100644 --- a/config/template.cmake +++ b/config/template.cmake @@ -1,9 +1,5 @@ @PACKAGE_INIT@ -set("@PROJECT_NAME@_WITH_CBOOL" @WITH_CBOOL@) -set("@PROJECT_NAME@_WITH_QP" @WITH_QP@) -set("@PROJECT_NAME@_WITH_XDP" @WITH_XDP@) - if(NOT TARGET "@PROJECT_NAME@::@PROJECT_NAME@") include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@-targets.cmake") endif() From b171ad688c0373ce94914f6befaf5d4723ab119c Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 16:58:30 +0200 Subject: [PATCH 3/8] mention of cmake in readme.md --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 8cd67ab..bec6994 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ Further updates are planned... To build this project from the source code in this repository you need to have a Fortran compiler supporting Fortran 2008 and one of the supported build systems: +- [cmake](https://cmake.org) version 3.14.0 or newer - [fpm](https://fpm.fortran-lang.org) version 0.3.0 or newer - [meson](https://mesonbuild.com) version 0.55 or newer, with a build-system backend, *i.e.* [ninja](https://ninja-build.org) version 1.7 or newer @@ -44,6 +45,21 @@ cd minpack ``` +#### Building with cmake + +Invoke cmake in the project root with + +``` +cmake -B build +cmake --build build +``` + +To run the testsuite use + +``` +cmake --build build --target test +``` + #### Building with fpm Invoke fpm in the project root with From 61e2c8498b7649b75b4acd176f62292de086220a Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 17:05:42 +0200 Subject: [PATCH 4/8] Add cmake in CI --- .github/workflows/CI.yml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4017180..f877fda 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -7,7 +7,7 @@ jobs: strategy: fail-fast: false matrix: - build: [fpm, meson] + build: [cmake, fpm, meson] os: [ubuntu-latest, macos-latest, windows-latest] gcc: [10] # Version of GFortran we want to use. build-type: [debug] @@ -71,6 +71,16 @@ jobs: extra-specs: | ${{ matrix.build-type == 'coverage' && 'gcovr' || '' }} + - name: Compile (cmake) + if: ${{ matrix.build == 'cmake' }} + run: | + cmake -B build + cmake --build build + + - name: Run test (cmake) + if: ${{ matrix.build == 'cmake' }} + run: cmake --build build --target test + - name: Compile (fpm) if: ${{ matrix.build == 'fpm' }} run: fpm build --profile release From 388e7ad945ee0bef4c2ca26ce2e768e89f42aa44 Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 17:16:00 +0200 Subject: [PATCH 5/8] Fix CI --- .github/workflows/CI.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f877fda..0321900 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -25,6 +25,7 @@ jobs: CC: gcc FPM_FC: gfortran FPM_CC: gcc + BUILD_DIR: ${{ matrix.build == 'cmake' && 'build' || '.' }} steps: - name: Checkout code uses: actions/checkout@v2 @@ -71,15 +72,20 @@ jobs: extra-specs: | ${{ matrix.build-type == 'coverage' && 'gcovr' || '' }} + - name: Configure (cmake) + if: ${{ matrix.build == 'cmake' }} + run: >- + cmake -Wdev + -DCMAKE_INSTALL_PREFIX=$PWD/_dist + -S . -B ${{ env.BUILD_DIR }} + - name: Compile (cmake) if: ${{ matrix.build == 'cmake' }} - run: | - cmake -B build - cmake --build build + cmake --build ${{ env.BUILD_DIR }} --parallel - name: Run test (cmake) if: ${{ matrix.build == 'cmake' }} - run: cmake --build build --target test + run: cmake --build ${{ env.BUILD_DIR }} --target test - name: Compile (fpm) if: ${{ matrix.build == 'fpm' }} From 61dcb49ecb4d6cebc99905dbb75fc71f1eea0c31 Mon Sep 17 00:00:00 2001 From: Jeremie Vandenplas Date: Fri, 12 Jul 2024 11:18:22 -0400 Subject: [PATCH 6/8] Update .github/workflows/CI.yml --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0321900..e950243 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -81,7 +81,7 @@ jobs: - name: Compile (cmake) if: ${{ matrix.build == 'cmake' }} - cmake --build ${{ env.BUILD_DIR }} --parallel + run: cmake --build ${{ env.BUILD_DIR }} --parallel - name: Run test (cmake) if: ${{ matrix.build == 'cmake' }} From f1c6fe26b9923b1e191ace6bea534b9f4fdd66c7 Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 17:19:42 +0200 Subject: [PATCH 7/8] fix CI --- .github/workflows/CI.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e950243..0385a2e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -81,7 +81,7 @@ jobs: - name: Compile (cmake) if: ${{ matrix.build == 'cmake' }} - run: cmake --build ${{ env.BUILD_DIR }} --parallel + run: cmake --build ${{ env.BUILD_DIR }} --parallel - name: Run test (cmake) if: ${{ matrix.build == 'cmake' }} From c0e9a2c50a5d025d7434bb5821f7b9bc9d463236 Mon Sep 17 00:00:00 2001 From: "Vandenplas, Jeremie" Date: Fri, 12 Jul 2024 17:22:43 +0200 Subject: [PATCH 8/8] fix CI --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0385a2e..b776196 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -67,6 +67,7 @@ jobs: - name: Install dependencies uses: mamba-org/provision-with-micromamba@main + if: ${{ matrix.build == 'fpm' || 'meson' }} with: environment-file: config/ci/${{ matrix.build }}-env.yaml extra-specs: |