Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CMakeCache.txt
CMakeFiles
Makefile
cmake_install.cmake
install_manifest.txt
8 changes: 6 additions & 2 deletions CorrectWindowsPaths.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
# unix-style paths into paths useable by cmake on windows

macro (CONVERT_CYGWIN_PATH _path)
if (WIN32)

# Some cygwin utilities (namely make) do not like DOS paths, but are happy with UNIX paths
# On the other hand out of the cygwin, the cygpath tool doesn't need to be available.

if (WIN32 AND NOT CYGWIN)
EXECUTE_PROCESS(COMMAND cygpath.exe -m ${${_path}}
OUTPUT_VARIABLE ${_path})
string (STRIP ${${_path}} ${_path})
endif (WIN32)
endif (WIN32 AND NOT CYGWIN)
endmacro (CONVERT_CYGWIN_PATH)

206 changes: 157 additions & 49 deletions FindPETSc.cmake

Large diffs are not rendered by default.

33 changes: 31 additions & 2 deletions FindPackageMultipass.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,21 @@
# # Make temporary files, run programs, etc, to determine FOO_INCLUDES and FOO_LIBRARIES
# endif (NOT foo_current)
#
# MULTIPASS_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS LANGUAGE)
# MULTIPASS_SOURCE_RUNS (INCLUDES LIBRARIES SOURCE RUNS LANGUAGE)
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale. The LANGUAGE
# variable is either C or CXX indicating which compiler the test should
# use.
# MULTIPASS_C_SOURCE_RUNS (Name INCLUDES LIBRARIES SOURCE RUNS)
#
# MULTIPASS_C_SOURCE_RUNS (INCLUDES LIBRARIES SOURCE RUNS)
# DEPRECATED! This is only included for backwards compatability. Use
# the more general MULTIPASS_SOURCE_RUNS instead.
# Always runs the given test, use this when you need to re-run tests
# because parent variables have made old cache entries stale.
#
# MULTIPASS_C_SOURCE_COMPILES(includes libraries source compiles)
# Same as MULTIPASS_C_SOURCE_RUNS but only check if the source compiles.
# TODO: make version for any language like MULTIPASS_SOURCE_RUNS

macro (FIND_PACKAGE_MULTIPASS _name _current)
string (TOUPPER ${_name} _NAME)
Expand Down Expand Up @@ -104,3 +109,27 @@ endmacro (MULTIPASS_SOURCE_RUNS)
macro (MULTIPASS_C_SOURCE_RUNS includes libraries source runs)
multipass_source_runs("${includes}" "${libraries}" "${source}" ${runs} "C")
endmacro (MULTIPASS_C_SOURCE_RUNS)


macro (MULTIPASS_C_SOURCE_COMPILES includes libraries source compiles)
include (CheckCSourceCompiles)
# This is a ridiculous hack. CHECK_C_SOURCE_* thinks that if the
# *name* of the return variable doesn't change, then the test does
# not need to be re-run. We keep an internal count which we
# increment to guarantee that every test name is unique. If we've
# gotten here, then the configuration has changed enough that the
# test *needs* to be rerun.
if (NOT MULTIPASS_TEST_COUNT)
set (MULTIPASS_TEST_COUNT 00)
endif (NOT MULTIPASS_TEST_COUNT)
math (EXPR _tmp "${MULTIPASS_TEST_COUNT} + 1") # Why can't I add to a cache variable?
set (MULTIPASS_TEST_COUNT ${_tmp} CACHE INTERNAL "Unique test ID")
set (testname MULTIPASS_TEST_${MULTIPASS_TEST_COUNT}_${compiles})
set (CMAKE_REQUIRED_INCLUDES ${includes})
set (CMAKE_REQUIRED_LIBRARIES ${libraries})
message(STATUS "check_c_source_compiles: ${testname}")
check_c_source_compiles ("${source}" ${testname})
set (${compiles} "${${testname}}")
endmacro (MULTIPASS_C_SOURCE_COMPILES)


89 changes: 89 additions & 0 deletions InstallPetsc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#InstallPetsc.cmake
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a precedent anywhere else for distributing InstallXXX.cmake files? If not, then I think this script is probably better distributed with your project where you can easily customize it, rather than in cmake-modules where I maintain it if it doesn't match the needs of some user.

#
# Created on: Jul 20, 2012
# Author: jb
#
# accepted variables:
# EXTERNAL_PETSC_DIR - target directory used for instalation
# INSTALL_PETSC_URL - url with petsc tarball
# PETSC_MPI_DIR - pass MPI to PETSC configure
# PETSC_LAPACK_DIR - pass Lapack to PETSC configure
# INSTALL_PETSC_ONLY - install only petsc (possibly MPI and BLAS/LAPACK)
# INSTALL_PETSC_OPTIONS - add content of this variable to the PETSC configure command
# (default) - install also, metis, parmetis



if (NOT EXTERNAL_PETSC_DIR)
set(EXTERNAL_PETSC_DIR "${EXTERNAL_PROJECT_DIR}/petsc_build")
endif()

##########################################################################
# Download PETSC
# A temporary CMakeLists.txt

# set configure line for PETSC
set(PETSC_CONF_LINE "--COPTFLAGS ${CMAKE_C_FLAGS} --CXXOPTFLAGS ${CMAKE_CXX_FLAGS} --with-clanguage=C --with-debugging=0")
if (CMAKE_Fortran_COMPILER)
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --FOPTFLAGS ${CMAKE_Fortran_FLAGS}")
endif()

if (PETSC_MPI_DIR)
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --with-mpi-dir=${PETSC_MPI_DIR}")
else()
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --download-mpich=yes")
endif()

if (PETSC_LAPACK_DIR)
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --with-lapack-dir=${PETSC_LAPACK_DIR}")
else()
if(CMAKE_Fortran_COMPILER)
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --download-f-blas-lapack=yes")
else()
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --download-c-blas-lapack=yes")
endif()
endif()

if(INSTALL_PETSC_ONLY)
else()
set(PETSC_CONF_LINE "${PETSC_CONF_LINE} --download-metis=yes --download-parmetis=yes")
endif()

set(PETSC_CONF_LINE "${PETSC_CONF_LINE} ${INSTALL_PETSC_OPTIONS}")

set (cmakelists_fname "${EXTERNAL_PETSC_DIR}/CMakeLists.txt")
file (WRITE "${cmakelists_fname}"
"
## This file was autogenerated by InstallPETSC.cmake
cmake_minimum_required(VERSION 2.8)
include(ExternalProject)
ExternalProject_Add(PETSC
DOWNLOAD_DIR ${EXTERNAL_PETSC_DIR}
URL ${INSTALL_PETSC_URL}
SOURCE_DIR ${EXTERNAL_PETSC_DIR}/src
BINARY_DIR ${EXTERNAL_PETSC_DIR}/src
CONFIGURE_COMMAND ${EXTERNAL_PETSC_DIR}/src/configure ${PETSC_CONF_LINE}
BUILD_COMMAND make all
INSTALL_COMMAND \"\"
)
")

message(STATUS "=== Installing PETSC ===")
# run cmake
set(PETSC_DIR "${EXTERNAL_PETSC_DIR}/src")
set(PETSC_ARCH "cmake")
set(ENV{PETSC_DIR} "${PETSC_DIR}")
set(ENV{PETSC_ARCH} "${PETSC_ARCH}")
execute_process(COMMAND ${CMAKE_COMMAND} ${EXTERNAL_PETSC_DIR}
WORKING_DIRECTORY ${EXTERNAL_PETSC_DIR})

find_program (MAKE_EXECUTABLE NAMES make gmake)
# run make
execute_process(COMMAND ${MAKE_EXECUTABLE} PETSC
WORKING_DIRECTORY ${EXTERNAL_PETSC_DIR})


#file (REMOVE ${cmakelists_fname})

message(STATUS "== PETSC build done")

4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cmake_modules
=============

CMake modules to detect and/or install specific libraries
88 changes: 51 additions & 37 deletions ResolveCompilerPaths.cmake
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
# ResolveCompilerPaths - this module defines two macros
#
# RESOLVE_LIBRARIES (XXX_LIBRARIES LINK_LINE)
# This macro is intended to be used by FindXXX.cmake modules.
# It parses a compiler link line and resolves all libraries
# (-lfoo) using the library path contexts (-L/path) in scope.
# The result in XXX_LIBRARIES is the list of fully resolved libs.
# Example:
# This macro is intended to be used by FindXXX.cmake modules.
# It parses a compiler link line and resolves all libraries
# (-lfoo) using the library path contexts (-L/path) in scope.
# The result in XXX_LIBRARIES is the list of fully resolved libs.
# Example:
#
# RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld")
# RESOLVE_LIBRARIES (FOO_LIBRARIES "-L/A -la -L/B -lb -lc -ld")
#
# will be resolved to
# will be resolved to
#
# FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so"
# FOO_LIBRARIES:STRING="/A/liba.so;/B/libb.so;/A/libc.so;/usr/lib/libd.so"
#
# if the filesystem looks like
# if the filesystem looks like
#
# /A: liba.so libc.so
# /B: liba.so libb.so
# /usr/lib: liba.so libb.so libc.so libd.so
# /A: liba.so libc.so
# /B: liba.so libb.so
# /usr/lib: liba.so libb.so libc.so libd.so
#
# and /usr/lib is a system directory.
# and /usr/lib is a system directory.
#
# Note: If RESOLVE_LIBRARIES() resolves a link line differently from
# the native linker, there is a bug in this macro (please report it).
# Note: If RESOLVE_LIBRARIES() resolves a link line differently from
# the native linker, there is a bug in this macro (please report it).
#
# RESOLVE_INCLUDES (XXX_INCLUDES INCLUDE_LINE)
# This macro is intended to be used by FindXXX.cmake modules.
# It parses a compile line and resolves all includes
# (-I/path/to/include) to a list of directories. Other flags are ignored.
# Example:
# This macro is intended to be used by FindXXX.cmake modules.
# It parses a compile line and resolves all includes
# (-I/path/to/include) to a list of directories. Other flags are ignored.
# Example:
#
# RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B")
# RESOLVE_INCLUDES (FOO_INCLUDES "-I/A -DBAR='\"irrelevant -I/string here\"' -I/B")
#
# will be resolved to
# will be resolved to
#
# FOO_INCLUDES:STRING="/A;/B"
# FOO_INCLUDES:STRING="/A;/B"
#
# assuming both directories exist.
# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
# assuming both directories exist.
# Note: as currently implemented, the -I/string will be picked up mistakenly (cry, cry)
include (CorrectWindowsPaths)

macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
Expand All @@ -53,24 +53,37 @@ macro (RESOLVE_LIBRARIES LIBS LINK_LINE)
list (APPEND _directory_list ${token})
elseif (token MATCHES "^(-l([^\" ]+|\"[^\"]+\")|[^\" ]+\\.(a|so|dll|lib))")
# It's a library, resolve the path by looking in the list and then (by default) in system directories
if (WIN32) #windows expects "libfoo", linux expects "foo"
if (WIN32 AND NOT CYGWIN) #windows expects "libfoo", linux expects "foo"
string (REGEX REPLACE "^-l" "lib" token ${token})
else (WIN32)
else ()
string (REGEX REPLACE "^-l" "" token ${token})
endif (WIN32)
set (_root)
if (token MATCHES "^/") # We have an absolute path
#separate into a path and a library name:
string (REGEX MATCH "[^/]*\\.(a|so|dll|lib)$" libname ${token})
string (REGEX MATCH ".*[^${libname}$]" libpath ${token})
convert_cygwin_path(libpath)
set (_directory_list ${_directory_list} ${libpath})
set (token ${libname})
endif ()

if (token MATCHES "^/") # We have an absolute path
#separate into a path and a library name:
if (WIN32 AND NOT CYGWIN) #windows expects "libfoo", linux expects "foo"
STRING(REGEX REPLACE "^/[^ ]*/([^/ ]*)[.](a|so|dll|lib)" "\\1" LIB_NAME ${token})
STRING(REGEX REPLACE "(^/[^ ]*/)[^/ ]*[.](a|so|dll|lib)" "\\1" LIB_PATH ${token})
else ()
STRING(REGEX REPLACE "^/[^ ]*/lib([^/ ]*).(a|so|dll)" "\\1" LIB_NAME ${token})
STRING(REGEX REPLACE "(^/[^ ]*/)lib[^/ ]*.(a|so|dll)" "\\1" LIB_PATH ${token})
endif ()

convert_cygwin_path(LIB_PATH)

set (_directory_list ${_directory_list} ${LIB_PATH})
set (token ${LIB_NAME})
endif (token MATCHES "^/")

set (_lib "NOTFOUND" CACHE FILEPATH "Cleared" FORCE)
find_library (_lib ${token} HINTS ${_directory_list} ${_root})
find_library (_lib NAMES ${token} HINTS ${_directory_list})
## debug
#message(STATUS "token: ${token}\ndlist: ${_directory_list}\nroot: ${_root}")
if (_lib)
string (REPLACE "//" "/" _lib ${_lib})
## debug
#message(STATUS "RESULT: ${_lib}")

string (REPLACE "//" "/" _lib ${_lib})
list (APPEND _libs_found ${_lib})
else (_lib)
message (STATUS "Unable to find library ${token}")
Expand Down Expand Up @@ -103,3 +116,4 @@ macro (RESOLVE_INCLUDES INCS COMPILE_LINE)
list (REMOVE_DUPLICATES _incs_found)
set (${INCS} "${_incs_found}")
endmacro (RESOLVE_INCLUDES)