Commit 0627b33d authored by Marco Clemencic's avatar Marco Clemencic
Browse files

modified the subdirectory dependency declaration to work across projects

Reviewed the dummy function to declare the dependencies and export the
collected dependencies to the client projects.
parent 42d74994
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building Gaudi
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
#---Executables-------------------------------------------------------------
gaudi_add_executable(Gaudi main.cpp LINK_LIBRARIES GaudiKernel)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiAlg
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiUtils GaudiKernel)
depends_on_subdirs(GaudiUtils GaudiKernel)
find_package(AIDA)
find_package(Boost COMPONENTS regex)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiAud
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
#---Libraries---------------------------------------------------------------
gaudi_add_module(GaudiAud *.cpp LINK_LIBRARIES GaudiKernel)
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(AIDA)
find_package(Boost COMPONENTS system filesystem)
......
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(Boost COMPONENTS system filesystem regex thread)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiExamples
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel GaudiUtils GaudiGSL GaudiAlg)
depends_on_subdirs(GaudiKernel GaudiUtils GaudiGSL GaudiAlg)
find_package(HepPDT)
find_package(ROOT COMPONENTS Tree RIO Hist)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiGSL
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiAlg)
depends_on_subdirs(GaudiAlg)
find_package(CLHEP)
find_package(GSL)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiKernel
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(Boost COMPONENTS program_options regex)
find_package(ROOT)
......
############################################################################
# CMakeLists.txt file for building GaudiMP
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(ROOT)
find_package(PythonLibs)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiMonitor
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
if(WIN32)
set(winsocklib ws2_32.lib)
......
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
gaudi_add_module(GaudiPartProp src/ParticlePropertySvc.cpp
LINK_LIBRARIES GaudiKernel)
############################################################################
# CMakeLists.txt file for building GaudiProfiling
############################################################################
require(GaudiKernel GaudiAlg)
depends_on_subdirs(GaudiKernel GaudiAlg)
if (CMAKE_SYSTEM_NAME MATCHES Linux)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiPython
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiAlg GaudiUtils GaudiKernel)
depends_on_subdirs(GaudiAlg GaudiUtils GaudiKernel)
find_package(CLHEP)
find_package(PythonLibs)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiSvc
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(AIDA)
find_package(Boost REQUIRED COMPONENTS regex)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building GaudiUtils
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(Boost)
find_package(AIDA)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building PartPropSvc
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(Boost COMPONENTS regex)
find_package(ROOT COMPONENTS Reflex)
......
require(GaudiKernel GaudiUtils)
depends_on_subdirs(GaudiKernel GaudiUtils)
find_package(ROOT COMPONENTS RIO Tree TreePlayer MathCore)
......
......@@ -2,7 +2,7 @@
# CMakeLists.txt file for building RootHistCnv
# @author Pere Mato, CERN (semi-automaticaly generated)
############################################################################
require(GaudiKernel)
depends_on_subdirs(GaudiKernel)
find_package(AIDA)
find_package(ROOT COMPONENTS RIO Hist Matrix Tree)
......
......@@ -211,7 +211,21 @@ macro(gaudi_project project version)
set(library_path)
# Take into account the dependencies between local subdirectories before
# adding them to the build.
gaudi_sort_subdirectories(packages)
gaudi_collect_subdir_deps(${packages})
# sort all known packages
gaudi_sort_subdirectories(known_packages)
# extract the local packages from the sorted list
set(sorted_packages)
foreach(var ${known_packages})
list(FIND packages ${var} idx)
if(NOT idx LESS 0)
list(APPEND sorted_packages ${var})
endif()
endforeach()
#message(STATUS "${known_packages}")
#message(STATUS "${packages}")
set(packages ${sorted_packages})
#message(STATUS "${packages}")
# Add all subdirectories to the project build.
foreach(package ${packages})
message(STATUS "Adding directory ${package}")
......@@ -396,32 +410,57 @@ function(include_package_directories)
endforeach()
endfunction()
# NO-OP function used by gaudi_sort_subdirectories to get the dependencies
# from the subdirectories before actually add them
function(depends_on_subdirs)
endfunction()
#-------------------------------------------------------------------------------
# gaudi_sort_subdirectories
# gaudi_collect_subdir_deps(subdirectories)
#
# look for dependencies declared in the subdirectories
#-------------------------------------------------------------------------------
# NO-OP function used by gaudi_sort_subdirectories
function(require)
endfunction()
# helper macros to collect the required subdirs
macro(gaudi_collect_subdir_deps)
foreach(_p ${ARGN})
# initialize dependencies variable
set(${_p}_DEPENDENCIES)
# parse the CMakeLists.txt
file(READ ${CMAKE_SOURCE_DIR}/${_p}/CMakeLists.txt file_contents)
string(REGEX MATCHALL "depends_on_subdirs *\\(([^)]+)\\)" vars ${file_contents})
foreach(var ${vars})
# extract the individual subdir names
string(REGEX REPLACE "depends_on_subdirs *\\(([^)]+)\\)" "\\1" __p ${var})
separate_arguments(__p)
foreach(___p ${__p})
# remove newlines in the matched subdir name
string(REGEX REPLACE "(\r?\n)+$" "" ___p "${___p}")
# check that the declared dependency refers to an existing (known) package
list(FIND known_packages ${___p} idx)
if(idx LESS 0)
message(WARNING "Subdirectory '${_p}' declare dependency on unknown subdirectory '${___p}'")
endif()
list(APPEND ${_p}_DEPENDENCIES ${___p})
endforeach()
endforeach()
endforeach()
endmacro()
# helper function used by gaudi_sort_subdirectories
macro(__visit__ _p)
if(NOT __${_p}_visited__)
set(__${_p}_visited__ 1)
#---list all dependent packages-----
if( EXISTS ${CMAKE_SOURCE_DIR}/${_p}/CMakeLists.txt)
file(READ ${CMAKE_SOURCE_DIR}/${_p}/CMakeLists.txt file_contents)
string(REGEX MATCHALL "require *\\(([^)]+)\\)" vars ${file_contents})
foreach(var ${vars})
string(REGEX REPLACE "require *\\(([^)]+)\\)" "\\1" __p ${var})
separate_arguments(__p)
foreach(___p ${__p})
__visit__(${___p})
endforeach()
set(__${_p}_visited__ TRUE)
if(${_p}_DEPENDENCIES)
foreach(___p ${${_p}_DEPENDENCIES})
__visit__(${___p})
endforeach()
set(out_packages ${out_packages} ${_p})
endif()
list(APPEND out_packages ${_p})
endif()
endmacro()
# Actual function
#-------------------------------------------------------------------------------
# gaudi_sort_subdirectories(var)
#
# Sort the list of subdirectories in the variable `var` according to the
# declared dependencies.
#-------------------------------------------------------------------------------
function(gaudi_sort_subdirectories var)
set(out_packages)
set(in_packages ${${var}})
......@@ -444,9 +483,10 @@ function(gaudi_get_packages var)
# ignore the source directory itself
if(NOT path STREQUAL CMakeLists.txt)
get_filename_component(package ${file} PATH)
SET(packages ${packages} ${package})
list(APPEND packages ${package})
endif()
endforeach()
list(SORT var)
set(${var} ${packages} PARENT_SCOPE)
endfunction()
......@@ -1508,6 +1548,9 @@ get_filename_component(_IMPORT_PREFIX \"\${_IMPORT_PREFIX}\" PATH)
file(APPEND ${pkg_exp_file} "add_library(${module} MODULE IMPORTED)\n")
endforeach()
if(${package}_DEPENDENCIES)
file(APPEND ${pkg_exp_file} "set(${package}_DEPENDENCIES ${${package}_DEPENDENCIES})\n")
endif()
endif()
install(FILES ${pkg_exp_file} DESTINATION cmake)
endforeach()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment