Merge pull request #171 from rolk/171_openmp
Refactor OpenMP support to be reusable
This commit is contained in:
44
cmake/Modules/Duplicates.cmake
Normal file
44
cmake/Modules/Duplicates.cmake
Normal file
@@ -0,0 +1,44 @@
|
||||
# - Remove duplicate library declarations
|
||||
#
|
||||
# Synopsis:
|
||||
#
|
||||
# remove_duplicate_libraries (module)
|
||||
#
|
||||
# where
|
||||
# module Name of the module whose libraries should be pruned
|
||||
|
||||
# Copyright (C) 2013 Uni Research AS
|
||||
# This file is licensed under the GNU General Public License v3.0
|
||||
|
||||
# libraries should always be trimmed from the beginning, so that also
|
||||
# missing functions in those later in the list will be resolved
|
||||
macro (remove_duplicate_libraries module)
|
||||
if (DEFINED ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
list (REMOVE_DUPLICATES ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
endif (DEFINED ${module}_LIBRARIES)
|
||||
endmacro (remove_duplicate_libraries module)
|
||||
|
||||
# headers can be trimmed from the end, since adding a directory to
|
||||
# the list is an idempotent action
|
||||
macro (remove_duplicate_headers module)
|
||||
if (DEFINED ${module}_INCLUDE_DIRS)
|
||||
list (REMOVE_DUPLICATES ${module}_INCLUDE_DIRS)
|
||||
endif (DEFINED ${module}_INCLUDE_DIRS)
|
||||
endmacro (remove_duplicate_headers module)
|
||||
|
||||
# linker flags may not be specified at all
|
||||
macro (remove_duplicate_flags module)
|
||||
if (DEFINED ${module}_LINKER_FLAGS)
|
||||
list (REMOVE_DUPLICATES ${module}_LINKER_FLAGS)
|
||||
endif (DEFINED ${module}_LINKER_FLAGS)
|
||||
endmacro (remove_duplicate_flags module)
|
||||
|
||||
# fix up both headers and libraries, in case two dependencies have
|
||||
# included the same second-level library independently
|
||||
macro (remove_dup_deps module)
|
||||
remove_duplicate_headers (${module})
|
||||
remove_duplicate_libraries (${module})
|
||||
remove_duplicate_flags (${module})
|
||||
endmacro (remove_dup_deps module)
|
||||
@@ -118,21 +118,8 @@ endif (UNIX)
|
||||
# dependencies
|
||||
|
||||
# parallel programming
|
||||
# enabling OpenMP is supposedly enough to make the compiler link with
|
||||
# the appropriate libraries
|
||||
find_package (OpenMP ${ERT_QUIET})
|
||||
list (APPEND ERT_LIBRARIES ${OpenMP_LIBRARIES})
|
||||
if (OPENMP_FOUND)
|
||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
|
||||
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
|
||||
endif (OPENMP_FOUND)
|
||||
|
||||
# threading library (search for this *after* OpenMP
|
||||
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package (Threads ${ERT_QUIET})
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
list (APPEND ERT_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif (CMAKE_USE_PTHREADS_INIT)
|
||||
include (UseOpenMP)
|
||||
find_openmp (ERT)
|
||||
|
||||
# compression library
|
||||
find_package (ZLIB ${ERT_QUIET})
|
||||
@@ -166,19 +153,8 @@ endif (UNIX)
|
||||
# since OpenMP often implies pthreads, we need to tidy up
|
||||
# (last instance of library must be left standing, thus reversing that
|
||||
# list before removing duplicates)
|
||||
if (ERT_INCLUDE_DIRS)
|
||||
list (REMOVE_DUPLICATES ERT_INCLUDE_DIRS)
|
||||
endif (ERT_INCLUDE_DIRS)
|
||||
if (ERT_LIBRARIES)
|
||||
list (REVERSE ERT_LIBRARIES)
|
||||
list (REMOVE_DUPLICATES ERT_LIBRARIES)
|
||||
list (REVERSE ERT_LIBRARIES)
|
||||
endif (ERT_LIBRARIES)
|
||||
|
||||
# linker flags may not be specified at all
|
||||
if (DEFINED ERT_LINKER_FLAGS)
|
||||
list (REMOVE_DUPLICATES ERT_LINKER_FLAGS)
|
||||
endif (DEFINED ERT_LINKER_FLAGS)
|
||||
include (Duplicates)
|
||||
remove_dup_deps (ERT)
|
||||
|
||||
# see if we can compile a minimum example
|
||||
# CMake logical test doesn't handle lists (sic)
|
||||
|
||||
@@ -31,16 +31,8 @@
|
||||
# "Boost COMPONENTS filesystem REQUIRED"
|
||||
# SUPERLU
|
||||
# )
|
||||
########################################################################
|
||||
#
|
||||
# - Remove duplicate library declarations
|
||||
#
|
||||
# Synopsis:
|
||||
#
|
||||
# remove_duplicate_libraries (module)
|
||||
#
|
||||
# where
|
||||
# module Name of the module whose libraries should be pruned
|
||||
|
||||
include (Duplicates)
|
||||
|
||||
# list of suffixes for all the project variables
|
||||
set (_opm_proj_vars
|
||||
@@ -108,13 +100,3 @@ endmacro (find_and_append_package_list_to prefix)
|
||||
macro (find_and_append_package_list)
|
||||
find_and_append_package_list_to (${CMAKE_PROJECT_NAME} ${ARGN})
|
||||
endmacro (find_and_append_package_list)
|
||||
|
||||
# libraries should always be trimmed from the beginning, so that also
|
||||
# missing functions in those later in the list will be resolved
|
||||
macro (remove_duplicate_libraries module)
|
||||
if (DEFINED ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
list (REMOVE_DUPLICATES ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
endif (DEFINED ${module}_LIBRARIES)
|
||||
endmacro (remove_duplicate_libraries module)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
# ${module}_LIBRARIES Directory of shared object files
|
||||
# ${module}_DEFINITIONS Defines that must be set to compile
|
||||
# ${module}_CONFIG_VARS List of defines that should be in config.h
|
||||
# ${module}_QUIET Verbosity of last find of this module
|
||||
# HAVE_${MODULE} Binary value to use in config.h
|
||||
#
|
||||
# Note: Arguments should be quoted, otherwise a list will spill into the
|
||||
@@ -36,16 +37,7 @@
|
||||
|
||||
# <http://www.vtk.org/Wiki/CMake:How_To_Find_Libraries>
|
||||
|
||||
# libraries should always be trimmed from the beginning, so that also
|
||||
# missing functions in those later in the list will be resolved
|
||||
macro (remove_duplicate_libraries module)
|
||||
if (DEFINED ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
list (REMOVE_DUPLICATES ${module}_LIBRARIES)
|
||||
list (REVERSE ${module}_LIBRARIES)
|
||||
endif (DEFINED ${module}_LIBRARIES)
|
||||
endmacro (remove_duplicate_libraries module)
|
||||
|
||||
include (Duplicates)
|
||||
# append all items from src into dst; both must be *names* of lists
|
||||
macro (append_found src dst)
|
||||
foreach (_item IN LISTS ${src})
|
||||
@@ -56,6 +48,13 @@ macro (append_found src dst)
|
||||
endmacro (append_found src dst)
|
||||
|
||||
function (find_opm_package module deps header lib defs prog conf)
|
||||
# variables to pass on to other packages
|
||||
if (FIND_QUIETLY)
|
||||
set (${module}_QUIET "QUIET")
|
||||
else (FIND_QUIETLY)
|
||||
set (${module}_QUIET "")
|
||||
endif (FIND_QUIETLY)
|
||||
|
||||
# if someone else has included this test, don't do it again
|
||||
if (${${module}_FOUND})
|
||||
return ()
|
||||
@@ -215,6 +214,7 @@ function (find_opm_package module deps header lib defs prog conf)
|
||||
set (${module}_DEFINITIONS "${${module}_DEFINITIONS}" PARENT_SCOPE)
|
||||
set (${module}_CONFIG_VARS "${${module}_CONFIG_VARS}" PARENT_SCOPE)
|
||||
set (${module}_LINKER_FLAGS "${${module}_LINKER_FLAGS}" PARENT_SCOPE)
|
||||
set (${module}_QUIET "${${module}_QUIET}" PARENT_SCOPE)
|
||||
set (HAVE_${MODULE} "${HAVE_${MODULE}}" PARENT_SCOPE)
|
||||
endfunction (find_opm_package module deps header lib defs prog conf)
|
||||
|
||||
@@ -225,6 +225,8 @@ function (debug_find_vars module)
|
||||
message (STATUS "${module}_LIBRARIES = ${${module}_LIBRARIES}")
|
||||
message (STATUS "${module}_DEFINITIONS = ${${module}_DEFINITIONS}")
|
||||
message (STATUS "${module}_CONFIG_VARS = ${${module}_CONFIG_VARS}")
|
||||
message (STATUS "${module}_LINKER_FLAGS = ${${module}_LINKER_FLAGS}")
|
||||
message (STATUS "${module}_QUIET = ${${module}_QUIET}")
|
||||
string (TOUPPER ${module} MODULE)
|
||||
string (REPLACE "-" "_" MODULE ${MODULE})
|
||||
message (STATUS "HAVE_${MODULE} = ${HAVE_${MODULE}}")
|
||||
|
||||
41
cmake/Modules/UseOpenMP.cmake
Normal file
41
cmake/Modules/UseOpenMP.cmake
Normal file
@@ -0,0 +1,41 @@
|
||||
# - Use OpenMP features
|
||||
#
|
||||
# Synopsis:
|
||||
#
|
||||
# find_openmp (module)
|
||||
#
|
||||
# where:
|
||||
#
|
||||
# module Name of the module to which OpenMP libraries
|
||||
# etc. should be added, e.g. "opm-core".
|
||||
#
|
||||
# Note: Compiler flags are always added globally, to avoid ABI
|
||||
# incompatibility problems.
|
||||
#
|
||||
# It is assumed that the following variables are available
|
||||
#
|
||||
# ${module}_QUIET Verbosity level of the parent's find module
|
||||
# ${module}_LIBRARIES List of libraries to which OpenMP will be added
|
||||
#
|
||||
# Example:
|
||||
# find_openmp (opm-core)
|
||||
# remove_dup_deps (opm-core)
|
||||
|
||||
include (AddOptions)
|
||||
macro (find_openmp opm)
|
||||
# enabling OpenMP is supposedly enough to make the compiler link with
|
||||
# the appropriate libraries
|
||||
find_package (OpenMP ${${opm}_QUIET})
|
||||
list (APPEND ${opm}_LIBRARIES ${OpenMP_LIBRARIES})
|
||||
if (OPENMP_FOUND)
|
||||
add_options (C ALL_BUILDS "${OpenMP_C_FLAGS}")
|
||||
add_options (CXX ALL_BUILDS "${OpenMP_CXX_FLAGS}")
|
||||
endif (OPENMP_FOUND)
|
||||
|
||||
# threading library (search for this *after* OpenMP
|
||||
set (CMAKE_THREAD_PREFER_PTHREAD TRUE)
|
||||
find_package (Threads ${${opm}_QUIET})
|
||||
if (CMAKE_USE_PTHREADS_INIT)
|
||||
list (APPEND ${opm}_LIBRARIES ${CMAKE_THREAD_LIBS_INIT})
|
||||
endif (CMAKE_USE_PTHREADS_INIT)
|
||||
endmacro (find_openmp opm)
|
||||
Reference in New Issue
Block a user