Do not duplicate handling of duplicate libraries

There were (at least) three implementations of the same macro; these
have been collected into a separate helper module. (Note that this
means that FindERT is now not completely stand-alone anymore).
This commit is contained in:
Roland Kaufmann
2013-03-05 13:50:58 +01:00
parent a2f13f1c3f
commit 911bf9593f
4 changed files with 49 additions and 43 deletions

View 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)

View File

@@ -166,19 +166,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)

View File

@@ -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)

View File

@@ -36,16 +36,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})