Specify source files explicitly rather than with glob

This commit is contained in:
Roland Kaufmann 2013-03-05 14:37:42 +01:00
parent 4877f9048f
commit 3af27c2130
3 changed files with 67 additions and 68 deletions

View File

@ -108,18 +108,10 @@ opm_auto_dirs ()
# put libraries in lib/
opm_out_dirs ()
# identify the compilation units in the library
# identify the compilation units in the library; sources in opm/,
# examples in examples/
opm_sources (${project})
# enumerate all testing programs in test/ directory
opm_find_tests ()
# tutorial programs are found in the tutorials/ directory
opm_find_tutorials ()
# example programs are found in the examples/ directory
opm_find_examples ()
# create configuration header which describes available features
# necessary to compile this library. singular version is the names that
# is required by this project alone, plural version transitively
@ -155,8 +147,7 @@ opm_cmake_config (${project})
# routines to build satellites such as tests, tutorials and samples
include (OpmSatellites)
# tutorial programs are found in the tutorials/ directory
opm_compile_satellites (${project} tutorial "" "")
# example programs are found in the examples/ directory
opm_compile_satellites (${project} examples "" "")
# infrastructure for testing
@ -164,7 +155,7 @@ enable_testing ()
include (CTest)
# make datafiles necessary for tests available in output directory
opm_data (tests datafiles "${tests_DIR}" "*.xml")
opm_data (tests datafiles "${tests_DIR}")
opm_compile_satellites (${project} tests "" "${tests_REGEXP}")
# use this target to run all tests

View File

@ -16,59 +16,72 @@ macro (opm_auto_dirs)
endmacro (opm_auto_dirs)
macro (opm_sources opm)
# find all the source code (note that these variables have name after
# the target library and not the project). the documentation recommends
# against using globs to enumerate source code, but if you list the
# files explicitly you'll change the build files every time you add to
# the project as well as having to rebuild completely anyway.
file (GLOB_RECURSE ${opm}_C_SOURCES "${${opm}_DIR}/[^.]*.c")
file (GLOB_RECURSE ${opm}_CXX_SOURCES "${${opm}_DIR}/[^.]*.cpp")
file (GLOB_RECURSE ${opm}_C_HEADERS "${${opm}_DIR}/[^.]*.h")
file (GLOB_RECURSE ${opm}_CXX_HEADERS "${${opm}_DIR}/[^.]*.hpp")
# remove pre-compile headers from output list
file (GLOB_RECURSE ${opm}_PRECOMP_CXX_HEADER "${${opm}_DIR}/${${opm}_NAME}-pch.hpp")
if ("${${opm}_PRECOMP_CXX_HEADER}" MATCHES ";")
message (FATAL_ERROR "There can only be one precompiled header!")
endif ("${${opm}_PRECOMP_CXX_HEADER}" MATCHES ";")
list (REMOVE_ITEM ${opm}_CXX_HEADERS
${PROJECT_SOURCE_DIR}/${${opm}_PRECOMP_CXX_HEADER}
)
# merge both languages into one compilation/installation
set (${opm}_SOURCES ${${opm}_C_SOURCES} ${${opm}_CXX_SOURCES})
set (${opm}_HEADERS ${${opm}_C_HEADERS} ${${opm}_CXX_HEADERS})
endmacro (opm_sources opm)
macro (opm_find_tests)
# every C++ program prefixed with test_ under tests/ directory should
# be automatically set up as a test
# this is necessary to set so that we know where we are going to
# execute the test programs (and make datafiles available)
set (tests_DIR "tests")
file (GLOB_RECURSE tests_SOURCES
"${tests_DIR}/test_*.cpp"
"${tests_DIR}/*_test.cpp"
)
file (GLOB_RECURSE not_tests_SOURCES
"${tests_DIR}/not-unit/test_*.cpp"
"${tests_DIR}/not-unit/*_test.cpp"
)
# how to retrieve the "fancy" name from the filename
set (tests_REGEXP
"^test_([^/]*)$"
"^([^/]*)_test$"
)
if (tests_SOURCES AND not_tests_SOURCES)
list (REMOVE_ITEM tests_SOURCES ${not_tests_SOURCES})
endif (tests_SOURCES AND not_tests_SOURCES)
endmacro (opm_find_tests)
macro (opm_find_tutorials)
# enumerate tutorials in project
set (tutorial_DIR "tutorials")
file (GLOB tutorial_SOURCES "${tutorial_DIR}/tutorial[0-9].cpp")
endmacro (opm_find_tutorials)
# start out with defined, empty lists which will be specified externally
set (MAIN_SOURCE_FILES)
set (EXAMPLE_SOURCE_FILES)
set (TEST_SOURCE_FILES)
set (TEST_DATA_FILES)
set (PUBLIC_HEADER_FILES)
macro (opm_find_examples)
set (examples_DIR "examples")
file (GLOB examples_SOURCES "${examples_DIR}/*.cpp")
endmacro (opm_find_examples)
# read the list of components from this file; it should set the above
# lists (which are generic names)
include (${PROJECT_SOURCE_DIR}/CMakeLists_files.cmake)
# rename from "friendly" names to ones that fit the "almost-structural"
# scheme used in the .cmake modules, converting them to absolute file
# names in the process
foreach (_file IN LISTS MAIN_SOURCE_FILES)
list (APPEND ${opm}_SOURCES ${PROJECT_SOURCE_DIR}/${_file})
endforeach (_file)
foreach (_file IN LISTS PUBLIC_HEADER_FILES)
list (APPEND ${opm}_HEADERS ${PROJECT_SOURCE_DIR}/${_file})
endforeach (_file)
foreach (_file IN LISTS TEST_SOURCE_FILES)
list (APPEND tests_SOURCES ${PROJECT_SOURCE_DIR}/${_file})
endforeach (_file)
foreach (_file IN LISTS TEST_DATA_FILES)
list (APPEND tests_DATA ${PROJECT_SOURCE_DIR}/${_file})
endforeach (_file)
foreach (_file IN LISTS EXAMPLE_SOURCE_FILES)
list (APPEND examples_SOURCES ${PROJECT_SOURCE_DIR}/${_file})
endforeach (_file)
# identify pre-compile header; if the project is called opm-foobar,
# then it should be in opm/foobar/opm-foobar-pch.hpp
string (REPLACE "-" "/" opm_NAME_AS_DIR ${${opm}_NAME})
set (${opm}_PRECOMP_CXX_HEADER "${opm_NAME_AS_DIR}/${${opm}_NAME}-pch.hpp")
if (NOT EXISTS ${PROJECT_SOURCE_DIR}/${${opm}_PRECOMP_CXX_HEADER})
set (${opm}_PRECOMP_CXX_HEADER "")
endif (NOT EXISTS ${PROJECT_SOURCE_DIR}/${${opm}_PRECOMP_CXX_HEADER})
endmacro (opm_sources opm)
# disable an entire directory from sources
macro (opm_disable_source opm)
foreach (_exp IN ITEMS ${ARGN})
# regexp or directory?
if (IS_ABSOLUTE "${_exp}")
set (_prefix "")
else (IS_ABSOLUTE "${_exp}")
set (_prefix "${PROJECT_SOURCE_DIR}/")
endif (IS_ABSOLUTE "${_exp}")
if (IS_DIRECTORY "${_prefix}${_exp}")
set (_glob "/*")
else (IS_DIRECTORY "${_prefix}${_exp}")
set (_glob "")
endif (IS_DIRECTORY "${_prefix}${_exp}")
file (GLOB_RECURSE _disabled RELATIVE ${PROJECT_SOURCE_DIR} "${_prefix}${_exp}${_glob}")
foreach (_file IN ITEMS ${_disabled})
list (REMOVE_ITEM ${opm}_SOURCES "${PROJECT_SOURCE_DIR}/${_file}")
endforeach (_file)
endforeach (_exp)
endmacro (opm_disable_source opm reldir)

View File

@ -108,9 +108,9 @@ endmacro (opm_compile_satellites opm prefix)
#
# Example:
#
# opm_data (tests datafiles "tests/" "*.xml")
# opm_data (tests datafiles "tests/")
#
macro (opm_data satellite target dirname files)
macro (opm_data satellite target dirname)
# even if there are no datafiles, create the directory so the
# satellite programs have a homedir to run in
execute_process (
@ -124,11 +124,6 @@ macro (opm_data satellite target dirname files)
# provide datafiles as inputs for the tests, by copying them
# to a tests/ directory in the output tree (if different)
set (${satellite}_INPUT_FILES)
set (${satellite}_DATA)
foreach (_fileset IN ITEMS ${files})
file (GLOB _fileset_DATA "${dirname}/${_fileset}")
list (APPEND ${satellite}_DATA ${_fileset_DATA})
endforeach (_fileset)
if (NOT PROJECT_SOURCE_DIR STREQUAL PROJECT_BINARY_DIR)
foreach (input_datafile IN LISTS ${satellite}_DATA)
file (RELATIVE_PATH rel_datafile "${PROJECT_SOURCE_DIR}" ${input_datafile})