diff --git a/CMakeLists.txt b/CMakeLists.txt index 442c61fde..af84d411d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,54 +16,24 @@ if (PETSC_DIR STREQUAL "") message (FATAL_ERROR "PETSc location (PETSC_DIR) is not defined") endif () -set (petsc_conf_variables "${PETSC_DIR}/lib/petsc/conf/variables") - -# Use existing variables from PETSc -# https://github.com/jedbrown/cmake-modules/blob/master/FindPETSc.cmake - -# Generate a temporary makefile to probe the PETSc configuration -# This file will be deleted once the settings from PETSc are parsed into CMake -exec_program (mktemp ARGS -d OUTPUT_VARIABLE TEMPDIR) -set (petsc_config_makefile "${TEMPDIR}/Makefile.petsc") -file (WRITE -"${petsc_config_makefile}" -"## This file was auto generated by CMake -# PETSC_DIR = ${PETSC_DIR} -SHELL = /bin/sh -include ${petsc_conf_variables} -INCLUDE_DIRS := \${PETSC_FC_INCLUDES} -LIBRARIES := \${PETSC_WITH_EXTERNAL_LIB} -includes: -\t@echo \${INCLUDE_DIRS} -extlibs: -\t@echo \${LIBRARIES} -") - -# CMake will execute each target in petsc_config_makefile to acquire corresponding PETSc Variables. -find_program (MAKE_EXECUTABLE NAMES gmake make) -execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "includes" - RESULT_VARIABLE PETSC_INCLUDES_RETURN - OUTPUT_VARIABLE petsc_includes - OUTPUT_STRIP_TRAILING_WHITESPACE) -execute_process (COMMAND ${MAKE_EXECUTABLE} --no-print-directory -f ${petsc_config_makefile} "extlibs" - RESULT_VARIABLE PETSC_EXTERNAL_LIB_RETURN - OUTPUT_VARIABLE petsc_external_lib - OUTPUT_STRIP_TRAILING_WHITESPACE) - -file (REMOVE_RECURSE ${TEMPDIR}) - -# Remove duplicate compiler and linker flags -string (REGEX MATCHALL "-I([^\" ]+)" TMP_LIST "${petsc_includes}") -list (REMOVE_DUPLICATES TMP_LIST) -foreach (dir ${TMP_LIST}) - set (PETSC_INCLUDES "${PETSC_INCLUDES} ${dir}") -endforeach (dir) +file (STRINGS "${PETSC_DIR}/lib/petsc/conf/petscvariables" petsc_external_lib REGEX "PETSC_WITH_EXTERNAL_LIB = .*$?") +string (REPLACE "=" ";" petsc_external_lib "${petsc_external_lib}") +list (GET petsc_external_lib 1 petsc_external_lib) string (REGEX MATCHALL "-[lLW]([^\" ]+)" TMP_LIST "${petsc_external_lib}") list (REMOVE_DUPLICATES TMP_LIST) foreach (exlib ${TMP_LIST}) set (PETSC_EXTERNAL_LIB "${PETSC_EXTERNAL_LIB} ${exlib}") endforeach (exlib) +file (STRINGS "${PETSC_DIR}/lib/petsc/conf/petscvariables" petsc_includes REGEX "PETSC_FC_INCLUDES = .*$?") +string (REPLACE "=" ";" petsc_includes "${petsc_includes}") +list (GET petsc_includes 1 petsc_includes) +string (REGEX MATCHALL "-I([^\" ]+)" TMP_LIST "${petsc_includes}") +list (REMOVE_DUPLICATES TMP_LIST) +foreach (dir ${TMP_LIST}) + set (PETSC_INCLUDES "${PETSC_INCLUDES} ${dir}") +endforeach (dir) + message ("PETSC_DIR:\n${PETSC_DIR}\n" ) message ("PETSC_INCLUDES:\n${PETSC_INCLUDES}\n" ) message ("PETSC_EXTERNAL_LIB:\n${PETSC_EXTERNAL_LIB}\n")