CMake modules for some scientific libraries

Overview

A collection of CMake modules, which can mostly be used independently.

The utilities for writing robust Find* modules might be useful until CMake takes static libraries and multiple active configurations seriously. See Improving Find* Modules.

Note for PETSc users: please consider using FindPkgConfig instead of FindPETSc.cmake from this package. PETSc has distributed petsc.pc for use by pkg-config since PETSc 3.4 and some corner cases were fixed in 3.12. Use of the provided petsc.pc is simpler for you distributing your package (only requires CMake default modules) and for us to maintain, especially when distributions modify the installation schema (so there is no PETSC_DIR).

Issues
  • use PATHS instead of HINTS in ResolveCompilerPaths

    use PATHS instead of HINTS in ResolveCompilerPaths

    For some reason, cmake finds the system library instead of the library specified from -L/path/to/lib when using HINTS, but it works fine with PATHS.

    This is probably some recent change in behavior (using the very recent cmake 3.5.2), because it used to work just fine. The docs say that PATHS should be used for hardcoded paths, which I guess the command-line flags sort of are, so this should be more correct in any case.

    opened by alexfikl 6
  • PETSc not discovered with empty PETSC_ARCH

    PETSc not discovered with empty PETSC_ARCH

    The fix of 2e65c1c788c to allow an absent PETSC_ARCH does not seem to work. From a bit of debugging it looks like that foreach (arch ${_petsc_arches}) skips over empty strings. Thus it does not try to the empty version of PETSC_ARCH.

    As fix I have tried adding

      if (NOT PETSC_ARCH)
        message (STATUS "Trying without PETSC_ARCH")
        find_path (petscconf petscconf.h
          HINTS ${PETSC_DIR}
          PATH_SUFFIXES include bmake
          NO_DEFAULT_PATH)
        if (petscconf)
          message (STATUS "Install without PETSC_ARCH found")
          set (PETSC_ARCH "" CACHE STRING "PETSc build architecture")
          set (PETSC_ARCH "")
        endif (petscconf)
      endif (NOT PETSC_ARCH)
      set (petscconf "NOTFOUND" CACHE INTERNAL "Scratch variable" FORCE)
    

    after the foreach loop that tries to detect the PETSC_ARCH.

    This fortunately fixes the problems on my system, though with my minimal knowledge of CMake I am far from sure if this is a/the correct solution to the problem. I have already noticed two things:

    • The line set (PETSC_ARCH "") is needed, otherwise PETSC_ARCH will remain at NOT_FOUND
    • Every time I run cmake again it will try to rediscover the PETSC_ARCH. I guess this happens due to that the check if discovery is needed (if (PETSC_DIR AND NOT PETSC_ARCH) on line 100) will be always be false on a system where PETSC_ARCH is empty.

    P.S. The system is a standard Arch Linux, where PETSc is installed using the AUR. Thus it is located in /opt/petsc/linux-c-opt/, with PETSC_DIR=/opt/petsc/linux-c-opt/ and no PETSC_ARCH set.

    opened by Laar 5
  • Couldn't find petsc at the SuperMUC HPC system

    Couldn't find petsc at the SuperMUC HPC system

    Hello,

    the petsc/3.8 module on the SuperMUC HPC system sets

    setenv          PETSC_DIR       /lrz/sys/libraries/petsc/3.8.2/Medium_Node/arch-linux-3-c-3.8.2-Medium_Node-real_mpi.intel_5.1_opt
    setenv          PETSC_ARCH      arch-linux-3-c-3.8.2-Medium_Node-real_mpi.intel_5.1_opt
    
    ls $PETSC_DIR
    bin  include  lib  share
    

    I am not sure if the environment is misconfigured or rather an edge case that should be fixed in FindPETSC.

    Thanks!

    opened by floli 5
  • Add more general search path for PETSc

    Add more general search path for PETSc

    Hit this while trying to build a program on HPC and a local workstation. Looks like some distros use a more general directory layout just sticking it in /usr/lib/petsc.

    opened by ptooley 5
  • Use netcdf statement in Fortran

    Use netcdf statement in Fortran

    Hi, I want to read a netcdf file using Fortran 90 and compling with gfortran. I'm seeing this error . Fatal error: can't open module file 'netcdf.mod' for reading at (1): no such file or directory I compiled using gfortran firstread.f90 -o first.x My source code looks like Program first read Use netcdf Implicit none Character (len=*), parameter :: f_name= " pr_historical.nc" Integer , parameter:: ndim=3, nlats=201, nlon=194 ...... .... end program firstread. Thanks

    opened by jidemutiu 3
  • Find.PETSc for LANGUAGES CXX

    Find.PETSc for LANGUAGES CXX

    Having project(preCICE LANGUAGES CXX C) at the top of my CMakeLists.txt, find_package(PETSc 3.6 REQUIRED) works fine.

    However, when I omit the C language, it fails. I am not entirely sure, if this is a bug, but since PETSc is used without problems inside this C++ only project, imho it should not need the C language flag.

    Thanks!

    Error is:

    -- The CXX compiler identification is GNU 7.2.0
    -- Check for working CXX compiler: /usr/bin/c++
    -- Check for working CXX compiler: /usr/bin/c++ -- works
    -- Detecting CXX compiler ABI info
    -- Detecting CXX compiler ABI info - done
    -- Detecting CXX compile features
    -- Detecting CXX compile features - done
    -- Build configuration: Debug
    -- Special platform settings: none
    -- petsc_lib_dir /home/floli/software/petsc/arch-linux2-c-debug/lib
    -- Recognized PETSc install with single library for all packages
    -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal
    CMake Error at /usr/share/cmake-3.9/Modules/CheckCSourceRuns.cmake:52 (try_run):
      Unknown extension ".c" for file
    
        /home/floli/precice/build/cmake-debug/CMakeFiles/CMakeTmp/src.c
    
      try_compile() works only for enabled languages.  Currently these are:
    
        CXX
    
      See project() command to enable other languages.
    Call Stack (most recent call first):
      cmake-modules/FindPackageMultipass.cmake:97 (check_c_source_runs)
      cmake-modules/FindPETSc.cmake:269 (multipass_source_runs)
      cmake-modules/FindPETSc.cmake:282 (petsc_test_runs)
      CMakeLists.txt:30 (find_package)
    
    
    -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal - Failed
    -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes
    CMake Error at /usr/share/cmake-3.9/Modules/CheckCSourceRuns.cmake:52 (try_run):
      Unknown extension ".c" for file
    
        /home/floli/precice/build/cmake-debug/CMakeFiles/CMakeTmp/src.c
    
      try_compile() works only for enabled languages.  Currently these are:
    
        CXX
    
      See project() command to enable other languages.
    Call Stack (most recent call first):
      cmake-modules/FindPackageMultipass.cmake:97 (check_c_source_runs)
      cmake-modules/FindPETSc.cmake:269 (multipass_source_runs)
      cmake-modules/FindPETSc.cmake:287 (petsc_test_runs)
      CMakeLists.txt:30 (find_package)
    
    
    -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes - Failed
    -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries
    CMake Error at /usr/share/cmake-3.9/Modules/CheckCSourceRuns.cmake:52 (try_run):
      Unknown extension ".c" for file
    
        /home/floli/precice/build/cmake-debug/CMakeFiles/CMakeTmp/src.c
    
      try_compile() works only for enabled languages.  Currently these are:
    
        CXX
    
      See project() command to enable other languages.
    Call Stack (most recent call first):
      cmake-modules/FindPackageMultipass.cmake:97 (check_c_source_runs)
      cmake-modules/FindPETSc.cmake:269 (multipass_source_runs)
      cmake-modules/FindPETSc.cmake:296 (petsc_test_runs)
      CMakeLists.txt:30 (find_package)
    
    
    -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries - Failed
    -- Performing Test MULTIPASS_TEST_4_petsc_works_all
    CMake Error at /usr/share/cmake-3.9/Modules/CheckCSourceRuns.cmake:52 (try_run):
      Unknown extension ".c" for file
    
        /home/floli/precice/build/cmake-debug/CMakeFiles/CMakeTmp/src.c
    
      try_compile() works only for enabled languages.  Currently these are:
    
        CXX
    
      See project() command to enable other languages.
    Call Stack (most recent call first):
      cmake-modules/FindPackageMultipass.cmake:97 (check_c_source_runs)
      cmake-modules/FindPETSc.cmake:269 (multipass_source_runs)
      cmake-modules/FindPETSc.cmake:303 (petsc_test_runs)
      CMakeLists.txt:30 (find_package)
    
    
    -- Performing Test MULTIPASS_TEST_4_petsc_works_all - Failed
    -- PETSc could not be used, maybe the install is broken.
    CMake Error at /usr/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      PETSc could not be found.  Be sure to set PETSC_DIR and PETSC_ARCH.
      (missing: PETSC_EXECUTABLE_RUNS) (found suitable version "3.8.1", minimum
      required is "3.6")
    Call Stack (most recent call first):
      /usr/share/cmake-3.9/Modules/FindPackageHandleStandardArgs.cmake:377 (_FPHSA_FAILURE_MESSAGE)
      cmake-modules/FindPETSc.cmake:331 (find_package_handle_standard_args)
      CMakeLists.txt:30 (find_package)
    
    
    -- Configuring incomplete, errors occurred!
    See also "/home/floli/precice/build/cmake-debug/CMakeFiles/CMakeOutput.log".
    See also "/home/floli/precice/build/cmake-debug/CMakeFiles/CMakeError.log".
    
    opened by floli 3
  • Fortran headers have new location in PETSc 3.6

    Fortran headers have new location in PETSc 3.6

    From PETSc 3.5 to 3.6 my Fortran code stopped compiling, even with the updated FindPETSc.cmake. I figured out it was because the Fortran headers moved from $PETSC_DIR/include/finclude to $PETSC_DIR/include/petsc/finclude. Therefore any F90 code with a statement like

    #include <finclude/petscsys.h>

    would need to be changed to

    #include <petsc/finclude/petscsys.h>

    in the source files which is a bit of work (hypothetically more for people with bigger codes than mine) and breaks the source from working with PETSc <=3.5. I attached a minimal example of a code that breaks from the 3.5 to 3.6 PETSc update. Note: I found a work around by changing the attached CMakeLists.txt by editing the line

    include_directories(${PETSC_INCLUDES})

    to become

    include_directories("${PETSC_INCLUDES}/petsc" "${PETSC_INCLUDES}")

    which works for both 3.5 and 3.6 without editing my F90 source files by simply exhaustively putting all the options of where finclude might be in the include path. While I am fine with this, I thought I'd post something to draw attention to the issue if you want to change it. For example, defining a PETSC_Fortran_INCLUDES variable in FindPETSc.cmake that automatically points to the fincludes directory regardless of the PETSc version would avoid the need for the above trick (though it does work).

    Here is the example: main.F90

    PROGRAM main #include <finclude/petscsys.h> PetscInt :: i END PROGRAM

    and CMakeLists.txt

    
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") # Where I have my FindPETSc.cmake
    
    cmake_minimum_required` (VERSION 2.8.8)
    project (HELLO)
    enable_language (Fortran)
    
    find_package(PETSc REQUIRED)
    include_directories(${PETSC_INCLUDES})
    
    find_package(MPI REQUIRED)
    add_definitions(${MPI_Fortran_COMPILE_FLAGS})
    include_directories(${MPI_Fortran_INCLUDE_PATH})
    link_directories(${MPI_Fortran_LIBRARIES})
    
    add_executable(main.x main.F90)
    target_link_libraries(main.x ${PETSC_LIBRARIES}  ${MPI_Fortran_LIBRARIES})
    
    opened by jkollasch 3
  • Added output variable to FindPETSc

    Added output variable to FindPETSc

    I order to link to PETSc I found that it was necessary to have access to what PETSc calls the external libraries. These seem to have the MPI symbols etc.

    It is possible to get around this by manually setting the compiler that cmake uses to the mpicc which is bundled with PETsc. According to the cmake documentation this is not the preferred method, so I added a variable to extract the external libraries include flags from PETSc.

    opened by jacobmerson 3
  • Can't find a working PETSc

    Can't find a working PETSc

    I tried to use the installed petsc (3.1) and one I compiled from source (3.6) but I can't get them to work. In both cases I get

    -- Recognized PETSc install with single library for all packages -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal -- Performing Test MULTIPASS_TEST_1_petsc_works_minimal - Failed -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes -- Performing Test MULTIPASS_TEST_2_petsc_works_allincludes - Failed -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries -- Performing Test MULTIPASS_TEST_3_petsc_works_alllibraries - Failed -- Performing Test MULTIPASS_TEST_4_petsc_works_all -- Performing Test MULTIPASS_TEST_4_petsc_works_all - Failed -- PETSc could not be used, maybe the install is broken.

    I am able to compile and run the examples in the petsc source.

    opened by burgerga 3
  • Added path to find version 3.2. on Debian wheezy

    Added path to find version 3.2. on Debian wheezy

    With these small changes PETSc version 3.2 is found on Debian wheezy, the development version of Debian. This might be of interest to other people, too.

    opened by blattms 3
  • Use PETSc MPIEXEC for doing tests in FindPETSc.cmake?

    Use PETSc MPIEXEC for doing tests in FindPETSc.cmake?

    On a machine like Summit at ORNL, executables built for the compute nodes need to be invoked via jsrun. I can get the tests that ship with PETSc to work by specifying --with-mpiexec=jsrun -a 1 -c 1 -g 1 at configure time. I'm wondering if it might be a good idea to have the tests that are run by the FindPETSc.cmake module use the MPIEXEC that is specified in the PETSc configuration. This should allow the FindPETSc module to work on Summit, instead of having to force PETSC_EXECUTABLE_RUNS to ON.

    I haven't written any CMake code in ten years and I don't remember how to do anything, so I don't know how hard it is to get CMake to grab the right things from the PETSc configuration or whether there might be some good reason to not want to do this.

    Update: I'm messing with FindPETSc.cmake because a project I'm working on uses that. I now see that @jedbrown's cmake-modules README states that we should probably be using FindPkgConfig instead. I have not used this and don't know if it makes the above issue moot, or if it will run into the same issue. (Does it need to run anything?)

    opened by rtmills 2
  • PETSC_ARCH and missing

    PETSC_ARCH and missing "/conf/PETScConfig.cmake")

    hi -

    I am compiling a software (gridpack) which depends on petsc. spack install petsc installs fine, but doesn't seem to have PETSC_ARCH set. The following messages suggests it is expecting another file: "${PETSC_DIR}/${PETSC_ARCH}/conf/PETScConfig.cmake")

    that I am not sure of its origin ... is there anything I am missing here?

    Thanks

    -- Checking PETSc ...
    CMake Error at /home/ubuntu/GridPACK/cmake-jedbrown/FindPETSc.cmake:151 (message):
      The pair
      PETSC_DIR=/home/ubuntu/spack/opt/spack/linux-ubuntu20.04-haswell/gcc-9.3.0/petsc-3.13.4-2bjevskgval6putbionc5ehmxeidsvnn
      PETSC_ARCH= do not specify a valid PETSc installation
    Call Stack (most recent call first):
      CMakeLists.txt:280 (find_package)
    
    
    -- Using PETSc version 3.13.4
    CMake Error at CMakeLists.txt:290 (message):
      PETSc found, but CMake configuration for PETSc installation not found?
    
    opened by python152 1
  • FindPETSc: failure on PETSC_ARCH with ^ character

    FindPETSc: failure on PETSC_ARCH with ^ character

    I have a petsc build on OSX with PETSC_ARCH=gcc-9.2.0^openmpi-3.1.1. The '^' character in the folder name seems to cause a call to echo in ${petsc_config_makefile} return bad data. Investigating a little more, it seems the behavior of 'echo' is notoriously non-portable, especially when used with flags and variables that contain dashes.

    Problem in FindPETSc.cmake Line 159: \[email protected] -n ${${VARIABLE}}

    Proposed solution: \[email protected] '%s' ${${VARIABLE}}

    The proposed solution solves my build error, I just wasn't sure if it would cause any issues with other build configurations.

    opened by nwukie 1
  • CMake ERROR: PETSC could not be found

    CMake ERROR: PETSC could not be found

    Dear, When using ccmake to install bitpit, I get the following error:

    CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message): PETSc could not be found. Be sure to set PETSC_DIR and PETSC_ARCH. (missing: PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) Call Stack (most recent call first): /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE) external/PETSc/cmake/FindPETSc.cmake:348 (find_package_handle_standard_args) CMakeLists.txt:524 (find_package)

    However, I have set all environmental variables (PETSC_DIR, PETSC_ARCH, PETSC_INCLUDES, PETSC_LIBRARIES and PETSC_EXECUTABLE_RUNS). Does anybody know how to solve this? Note: my os is ubuntu 18.04

    opened by JanssensNick 3
  • Find PETSc fails

    Find PETSc fails

    I'm trying to use the CMake module to find the PETSc installation that I built on Ubuntu 19.04. I am setting both environment and CMake variables for PETSC_DIR and PETSC_ARCH but I still get the following error message:

    -- PETSC_DIR: /petsc
    -- PETSC_ARCH: mpi-real-double
    CMake Error at /usr/share/cmake-3.13/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
      PETSc could not be found.  Be sure to set PETSC_DIR and PETSC_ARCH.
      (missing: PETSC_INCLUDES PETSC_LIBRARIES PETSC_EXECUTABLE_RUNS) (found
      version "3.11.1")
    

    Any ideas?

    opened by jmonschke-onscale 1
  • FindPETSc tests fail with missing include <mpi.h>

    FindPETSc tests fail with missing include

    FindPETSc does not respect MPI include paths and therefore fails to compile the tests on systems with scoped mpi installs such as OpenMPI on Ubuntu 16.04 (/usr/include/openmpi/mpi.h)

    It should include MPI_INCLUDE_DIRS, or similar here. https://github.com/jedbrown/cmake-modules/blob/91f96174a8b3f65e19519fa592b1571391c0e3d0/FindPETSc.cmake#L292

    A possible solution is to adapt FindPETSc to call FindMPI internally.

    opened by fsimonis 5
Owner
Jed Brown
Physical Prediction, Inference, & Design (PhyPID). Fast algorithms & community software. Asst Prof at CU Boulder. Alpinist, skier, runner. he/him
Jed Brown
CMake modules to help use sanitizers

sanitizers-cmake CMake module to enable sanitizers for binary targets. Include into your project To use FindSanitizers.cmake, simply add this reposito

Matt Arsenault 274 Jun 14, 2022
CMake Community Modules

CMake Community Modules The CMake Community Modules are CMake modules created and maintained by the community. This repository's main product is the C

Edgar 1 May 12, 2022
Extra CMake Modules for YARP and friends

YCM Extra CMake Modules for YARP and friends Documentation Online documentation is available

Robotology 41 Mar 30, 2022
Extra modules and scripts for CMake.

Extra CMake Modules Introduction The Extra CMake Modules package, or ECM, adds to the modules provided by CMake, including ones used by find_package()

KDE GitHub Mirror 100 Jun 12, 2022
Common CMake modules

CMake Modules This repository contains common CMake modules and a collection of find scripts to locate non-CMake dependencies. The recommended way to

Eyescale Software GmbH 143 Jun 4, 2022
Additional CMake functionality. Most of the modules are from Ryan Pavlik

Additional CMake functionality. Most of the modules are from Ryan Pavlik

Lars Bilke 413 Jun 23, 2022
Ryan's CMake Modules Collection

This is a collection of CMake modules that I've produced during the course of a variety of software development.

Ryan A. Pavlik 845 Jun 22, 2022
A set of cmake modules to assist in building code

CMake 3 Tools Warning: These tools are being replaced by the Modern CMake. Some of the tools are still being maintained for now, but new projects shou

null 181 Jun 4, 2022
CMake scripts for building OpenSceneGraph third party libraries.

osg-3rdparty-cmake CMake scripts for building OpenSceneGraph third party libraries. These scripts can be used to build third party libraries from sour

Björn Blissing 150 Jun 25, 2022
CMake BASIS makes it easy to create sharable software and libraries that work together

CMake BASIS makes it easy to create sharable software and libraries that work together. This is accomplished by combining and documenting some of the best practices and utilities available. This project supplies a fully integrated suite of functionality to make the whole process seamless!

CMake BASIS 38 Feb 25, 2022
This is a simple CMake tutorial project which contains some different scenarios

learning-cmake This is a simple CMake tutorial project which contains some different scenarios. hello-world: Demo a simplest CMake project. hello-worl

Bob Liu 2.7k Jun 24, 2022
📦 CMake's missing package manager. A small CMake script for setup-free, cross-platform, reproducible dependency management.

Setup-free CMake dependency management CPM.cmake is a CMake script that adds dependency management capabilities to CMake. It's built as a thin wrapper

CPM.cmake 1.2k Jun 27, 2022
CMake scripts for painless usage of SuiteSparse+METIS from Visual Studio and the rest of Windows/Linux/OSX IDEs supported by CMake

CMake scripts for painless usage of Tim Davis' SuiteSparse (CHOLMOD,UMFPACK,AMD,LDL,SPQR,...) and METIS from Visual Studio and the rest of Windows/Lin

Jose Luis Blanco-Claraco 379 Jun 23, 2022
cmake-font-lock - Advanced, type aware, highlight support for CMake

cmake-font-lock - Advanced, type aware, highlight support for CMake

Anders Lindgren 37 Dec 30, 2021
cmake-avr - a cmake toolchain for AVR projects

cmake-avr - a cmake toolchain for AVR projects Testing the example provided The toolchain was created and tested within the following environment: Lin

Matthias Kleemann 156 Jun 20, 2022
Make CMake less painful when trying to write Modern Flexible CMake

Izzy's eXtension Modules IXM is a CMake library for writing Modern flexible CMake. This means: Reducing the amount of CMake written Selecting reasonab

IXM 99 Feb 14, 2022
CMake module to enable code coverage easily and generate coverage reports with CMake targets.

CMake-codecov CMake module to enable code coverage easily and generate coverage reports with CMake targets. Include into your project To use Findcodec

HPC 76 Jun 1, 2022
unmaintained - CMake module to activate certain C++ standard, feature checks and appropriate automated workarounds - basically an improved version of cmake-compile-features

Compatibility This library provides an advanced target_compile_features() and write_compiler_detection_header(). The problem with those is that they a

Jonathan Müller 72 Apr 14, 2022
[CMake] [BSD-2] CMake module to find ICU

FindICU.cmake A CMake module to find International Components for Unicode (ICU) Library Note that CMake, since its version 3.7.0, includes a FindICU m

julp 29 Apr 26, 2022