jedbrown/cmake-modules

PETSC_VERSION not set when cmake run second time

Closed this issue · 2 comments

floli commented

Hello,

I have

find_package(PETSc 3.6 REQUIRED)
add_definitions(-DPETSC_MAJOR=${PETSC_VERSION_MAJOR} -DPETSC_MINOR=${PETSC_VERSION_MINOR})
message("PETSC VERSION: " ${PETSC_VERSION} )
message("PETSC VERSION: " ${PETSC_VERSION_MAJOR} " . " ${PETSC_VERSION_MINOR} )

To use some conditional compiling based on the PETSc version. (if there is a better way, let me know please!)

It works fine when cmake is ran on an empty directory:

% cmake ../..
[...]
-- petsc_lib_dir /home/florian/software/petsc/arch-linux2-c-debug/lib
-- 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 - Success
-- PETSc requires extra include paths, but links correctly with only interface libraries.  This is an unexpected configuration (but it seems to work fine).
-- Found PETSc: /home/florian/software/petsc/include;/home/florian/software/petsc/arch-linux2-c-debug/include;/opt/mpich/include (found suitable version "3.8.4", minimum required is "3.6")
PETSC VERSION: 3.8.4
PETSC VERSION: 3 . 8

The define is also set correctly. But when I run the same command a second time

% cmake ../..
-- Build configuration: Debug
-- Special platform settings: none
-- Found PETSc: /home/florian/software/petsc/include;/home/florian/software/petsc/arch-linux2-c-debug/include;/opt/mpich/include (Required is at least version "3.6")
PETSC VERSION:
PETSC VERSION:  .

The values are empty. Also the defines for the following make are set to empty values.

Not really sure, if that is a problem of my config, or cmake or the module...

Thanks!

Either petsc_get_version needs to be cached (and cleared if the wrong PETSc was found) or it needs to be called when petsc_config_current. You could work around it by caching the variable on your end. I'm sorry, but I haven't used this module in several years and don't have time to test or investigate whether recommended practice has changed. I'm happy to review and merge PRs.

floli commented

Applying that fix I get:

CMake Error at tools/cmake-modules/FindPETSc.cmake:71 (set):
  set given invalid arguments for CACHE mode.
Call Stack (most recent call first):
  tools/cmake-modules/FindPETSc.cmake:144 (petsc_get_version)
  CMakeLists.txt:32 (find_package)


-- petsc_lib_dir /home/florian/software/petsc/arch-linux2-c-debug/lib
-- 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.
CMake Error at tools/cmake-modules/FindPETSc.cmake:327 (if):
  if given arguments:

    "VERSION_LESS" "3.1"

  Unknown arguments specified
Call Stack (most recent call first):
  CMakeLists.txt:32 (find_package)


-- Configuring incomplete, errors occurred!

CMake 3.10.3

I will try to investigate myself, but I am also open to any input.