Skip to content

Commit 013377d

Browse files
author
Roberto Di Remigio
committed
Update CMake infrastructure: both Autocmake and custom modules
1 parent da69f3a commit 013377d

File tree

14 files changed

+89
-80
lines changed

14 files changed

+89
-80
lines changed

CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ include(autocmake_omp)
4141
include(autocmake_safeguards)
4242
include(autocmake_python_interpreter)
4343
include(pcmsolver)
44-
include(boost_version-components)
4544
include(autocmake_boost)
4645
include(version)
4746
include(catch)

cmake/autocmake.cfg

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ source: https://github.com/scisoft/autocmake/raw/master/modules/python_interpret
4444
[top_level]
4545
source: custom/pcmsolver.cmake
4646

47-
[custom_boost]
48-
source: custom/boost_version-components.cmake
49-
5047
[boost]
48+
override: {'major': 1, 'minor': 54, 'patch': 0, 'components': 'chrono;timer;system'}
5149
source: https://github.com/scisoft/autocmake/raw/master/modules/boost/boost.cmake
52-
fetch: http://sourceforge.net/projects/boost/files/boost/1.54.0/boost_1_54_0.zip
5350

5451
[general]
5552
source: custom/version.cmake

cmake/custom/api.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
include_directories(${PROJECT_SOURCE_DIR}/api)
22

3-
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/include)
4-
5-
file(COPY ${PROJECT_SOURCE_DIR}/api/pcmsolver.h DESTINATION ${PROJECT_BINARY_DIR}/include)
3+
install(FILES ${PROJECT_SOURCE_DIR}/api/pcmsolver.h DESTINATION include)
64

75
if(ENABLE_FORTRAN_API)
86
set_property(GLOBAL APPEND PROPERTY PCMSolver_Fortran_SOURCES ${PROJECT_SOURCE_DIR}/api/pcmsolver.F90)

cmake/custom/boost_version-components.cmake

Lines changed: 0 additions & 5 deletions
This file was deleted.

cmake/custom/eigen.cmake

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
set(EIGEN3_ROOT ${PROJECT_SOURCE_DIR}/external/eigen3)
2-
set(EIGEN3_INCLUDE_DIR ${EIGEN3_ROOT}/include/eigen3)
3-
install(DIRECTORY ${PROJECT_SOURCE_DIR}/external/eigen3 DESTINATION ${PROJECT_BINARY_DIR}/external/include)
4-
message(STATUS "Eigen 3.2.0 is located here: " ${PROJECT_BINARY_DIR}/external/include/eigen3)
1+
set(EIGEN3_INCLUDE_DIR ${PROJECT_SOURCE_DIR}/external/eigen3/include/eigen3)
2+
message(STATUS "Eigen 3.2.0 is located here: " ${EIGEN3_INCLUDE_DIR})
53
include_directories(SYSTEM ${EIGEN3_INCLUDE_DIR})
64

75
if(ENABLE_EIGEN_MKL)

cmake/custom/libgetkw.cmake

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ include(ExternalProject)
22

33
set(GetkwCMakeArgs
44
-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
5-
-DCMAKE_INSTALL_PREFIX=${PROJECT_BINARY_DIR}/external
5+
-DCMAKE_INSTALL_PREFIX=${SUBMODULES_INSTALL_PREFIX}
66
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
77
-DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
88
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
@@ -16,14 +16,14 @@ ExternalProject_Add(libgetkw
1616
BINARY_DIR ${PROJECT_BINARY_DIR}/external/libgetkw-build
1717
STAMP_DIR ${PROJECT_BINARY_DIR}/external/libgetkw-stamp
1818
TMP_DIR ${PROJECT_BINARY_DIR}/external/libgetkw-tmp
19-
INSTALL_DIR ${PROJECT_BINARY_DIR}/external
19+
INSTALL_DIR ${SUBMODULES_INSTALL_PREFIX}
2020
CMAKE_ARGS ${GetkwCMakeArgs}
2121
)
2222

2323
if(BUILD_CUSTOM_BOOST)
2424
add_dependencies(libgetkw custom_boost)
2525
endif()
2626

27-
link_directories(${PROJECT_BINARY_DIR}/external/lib)
27+
link_directories(${SUBMODULES_INSTALL_PREFIX}/lib)
2828

29-
set(GETKW_PYTHON_DIR ${PROJECT_BINARY_DIR}/external/share/libgetkw)
29+
set(GETKW_PYTHON_DIR ${SUBMODULES_INSTALL_PREFIX}/share/libgetkw)

cmake/custom/pcmsolver.cmake

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ option(ENABLE_TIMER "Enable timer" ON)
33
option(BUILD_STANDALONE "Enable build of standalone executables" ON)
44
option(ENABLE_FORTRAN_API "Builds optional Fortran90 API" OFF)
55

6+
# This can be set by the host project
7+
# and tweaks the location of the submodules install location
8+
if(NOT DEFINED SUBMODULES_INSTALL_PREFIX)
9+
set(SUBMODULES_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/external)
10+
endif()
11+
612
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
713
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
814

@@ -15,5 +21,5 @@ set_property(GLOBAL PROPERTY PCMSolver_Fortran_SOURCES)
1521
# PCMSolver headers
1622
set_property(GLOBAL PROPERTY PCMSolver_HEADER_DIRS)
1723

18-
include_directories(SYSTEM ${PROJECT_BINARY_DIR}/external/include)
1924
include_directories(${PROJECT_BINARY_DIR}/include)
25+
include_directories(SYSTEM ${SUBMODULES_INSTALL_PREFIX}/include)

cmake/downloaded/autocmake_boost.cmake

Lines changed: 33 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
11
#.rst:
22
#
3-
# Boost libraries detection and automatic build-up.
4-
# Minimum required version of Boost and required components have to
5-
# be specified separately in ``custom/boost_version-components.cmake``
6-
# By "required components" we here mean compiled Boost libraries.
7-
# This modules downloads the .zip archive from sourceforge at project
8-
# bootstrap.
9-
# Your autocmake.cfg should look like this::
3+
# Detect, build, and link Boost libraries.
4+
# This modules downloads the .zip archive from SourceForge
5+
# Autocmake update time.
106
#
11-
# [custom]
12-
# source: custom/boost_version-components.cmake
7+
# Your autocmake.cfg should look like this::
138
#
149
# [boost]
10+
# override: {'major': 1, 'minor': 59, 'patch': 0, 'components': 'chrono;timer;system'}
1511
# source: https://github.com/scisoft/autocmake/raw/master/modules/boost/boost.cmake
16-
# fetch: http://sourceforge.net/projects/boost/files/boost/1.58.0/boost_1_58_0.zip
17-
#
18-
# The ``custom/boost_version-components.cmake`` should look like this::
19-
#
20-
# set(BOOST_MINIMUM_REQUIRED 1.58.0)
21-
# list(APPEND BOOST_COMPONENTS_REQUIRED chrono timer system)
2212
#
23-
# Caveats:
24-
#
25-
# #. cross-dependencies between required components are not checked for.
26-
# For example, Boost.Timer depends on Boost.Chrono and Boost.System thus you
27-
# should ask explicitly for all three
28-
# #. the project admin has to make sure that ``BOOST_MINIMUM_REQUIRED`` and the
29-
# ``fetch`` directive point to the same version of Boost
13+
# Cross-dependencies between required components are not checked for.
14+
# For example, Boost.Timer depends on Boost.Chrono and Boost.System thus you
15+
# should ask explicitly for all three.
3016
#
3117
# Dependencies::
3218
#
@@ -35,35 +21,40 @@
3521
#
3622
# Variables used::
3723
#
38-
# BOOST_MINIMUM_REQUIRED - Minimum required version of Boost, set in ``custom/boost_version-components.cmake``
24+
# BOOST_MINIMUM_REQUIRED - Minimum required version of Boost
3925
# BOOST_COMPONENTS_REQUIRED - Components (compiled Boost libraries) required
4026
# PROJECT_SOURCE_DIR
4127
# PROJECT_BINARY_DIR
4228
# CMAKE_BUILD_TYPE
4329
# MPI_FOUND
4430
#
45-
# Variables set::
46-
#
4731
# autocmake.cfg configuration::
4832
#
33+
# major=1
34+
# minor=48
35+
# patch=0
36+
# components=''
4937
# fetch: https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_unpack.cmake
5038
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_userconfig.cmake
5139
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_configure.cmake
5240
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_build.cmake
5341
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_install.cmake
5442
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_headers.cmake
5543
# https://github.com/scisoft/autocmake/raw/master/modules/boost/boost_cleanup.cmake
44+
# http://sourceforge.net/projects/boost/files/boost/%(major)s.%(minor)s.%(patch)s/boost_%(major)s_%(minor)s_%(patch)s.zip
5645
# docopt: --boost-headers=<BOOST_INCLUDEDIR> Include directories for Boost [default: ''].
5746
# --boost-libraries=<BOOST_LIBRARYDIR> Library directories for Boost [default: ''].
5847
# --build-boost=<FORCE_CUSTOM_BOOST> Deactivate Boost detection and build on-the-fly <ON/OFF> [default: OFF].
59-
# define: '-DBOOST_INCLUDEDIR="%s"' % arguments['--boost-headers']
60-
# '-DBOOST_LIBRARYDIR="%s"' % arguments['--boost-libraries']
61-
# '-DFORCE_CUSTOM_BOOST="%s"' % arguments['--build-boost']
48+
# define: '-DBOOST_INCLUDEDIR="{0}"'.format(arguments['--boost-headers'])
49+
# '-DBOOST_LIBRARYDIR="{0}"'.format(arguments['--boost-libraries'])
50+
# '-DFORCE_CUSTOM_BOOST="{0}"'.format(arguments['--build-boost'])
51+
# '-DBOOST_MINIMUM_REQUIRED="%(major)s.%(minor)s.%(patch)s"'
52+
# '-DBOOST_COMPONENTS_REQUIRED="%(components)s"'
6253

6354
# FIXME Maintainer should be able to choose between fail (end-user has to satisfy dependency
6455
# on its own) and soft-fail (self-build of Boost)
6556
# Underscore-separated version number
66-
string(REGEX REPLACE "\\." "_" BOOSTVER ${BOOST_MINIMUM_REQUIRED})
57+
string(REGEX REPLACE "\\." "_" BOOSTVER ${BOOST_MINIMUM_REQUIRED})
6758
# Where the Boost .zip archive is located
6859
set(BOOST_ARCHIVE_LOCATION ${CMAKE_CURRENT_LIST_DIR})
6960
set(BOOST_ARCHIVE boost_${BOOSTVER}.zip)
@@ -82,12 +73,12 @@ if(FORCE_CUSTOM_BOOST)
8273
# Just to avoid unused variable warning from CMake
8374
set(BOOST_INCLUDEDIR "")
8475
set(BOOST_LIBRARYDIR "")
85-
else(FORCE_CUSTOM_BOOST)
76+
else()
8677
find_package(Boost ${BOOST_MINIMUM_REQUIRED} COMPONENTS "${BOOST_COMPONENTS_REQUIRED}")
8778
if(NOT Boost_FOUND)
8879
set(BUILD_CUSTOM_BOOST TRUE)
89-
endif(NOT Boost_FOUND)
90-
endif(FORCE_CUSTOM_BOOST)
80+
endif()
81+
endif()
9182

9283
if(BUILD_CUSTOM_BOOST)
9384
## Preliminary work
@@ -112,7 +103,8 @@ if(BUILD_CUSTOM_BOOST)
112103
string(TOLOWER ${CMAKE_BUILD_TYPE} type)
113104
include(${CMAKE_CURRENT_LIST_DIR}/boost_unpack.cmake)
114105
include(${CMAKE_CURRENT_LIST_DIR}/boost_userconfig.cmake)
115-
if(BOOST_COMPONENTS_REQUIRED)
106+
107+
if(NOT BOOST_COMPONENTS_REQUIRED STREQUAL "")
116108
# Non-empty list. Compiled libraries needed
117109
# Transform the ;-separated list to a ,-separated list (digested by the Boost build toolchain!)
118110
string(REPLACE ";" "," b2_needed_components "${BOOST_COMPONENTS_REQUIRED}")
@@ -125,12 +117,13 @@ if(BUILD_CUSTOM_BOOST)
125117
include(${CMAKE_CURRENT_LIST_DIR}/boost_configure.cmake)
126118
include(${CMAKE_CURRENT_LIST_DIR}/boost_build.cmake)
127119
include(${CMAKE_CURRENT_LIST_DIR}/boost_install.cmake)
128-
else(BOOST_COMPONENTS_REQUIRED)
120+
else()
129121
# Empty list. Header-only libraries needed
130122
# Just unpack to known location
131123
message(STATUS " No libraries required, installing headers")
132124
include(${CMAKE_CURRENT_LIST_DIR}/boost_headers.cmake)
133-
endif(BOOST_COMPONENTS_REQUIRED)
125+
endif()
126+
134127
include(${CMAKE_CURRENT_LIST_DIR}/boost_cleanup.cmake)
135128
add_custom_target(custom_boost DEPENDS ${CUSTOM_BOOST_LOCATION}/boost.cleanedup)
136129
# 4. Set all variables related to Boost that find_package would have set
@@ -142,6 +135,7 @@ if(BUILD_CUSTOM_BOOST)
142135
set(Boost_LIB_VERSION ${Boost_MAJOR_VERSION}_${Boost_MINOR_VERSION})
143136
set(Boost_INCLUDE_DIR ${CUSTOM_BOOST_LOCATION}/include CACHE PATH "Boost include directory" FORCE)
144137
set(Boost_LIBRARY_DIR ${CUSTOM_BOOST_LOCATION}/lib CACHE PATH "Boost library directory" FORCE)
138+
145139
foreach(_component ${BOOST_COMPONENTS_REQUIRED})
146140
string(TOUPPER ${_component} _COMP)
147141
set(Boost_${_COMP}_FOUND TRUE)
@@ -150,11 +144,14 @@ if(BUILD_CUSTOM_BOOST)
150144
set(Boost_${_COMP}_LIBRARY_RELEASE ${Boost_LIBRARY_DIR}/${Boost_${_COMP}_LIBRARY} CACHE FILEPATH "Boost ${_component} library (release)" FORCE)
151145
list(APPEND Boost_LIBRARIES ${Boost_${_COMP}_LIBRARY})
152146
endforeach()
147+
153148
set(Boost_INCLUDE_DIRS ${Boost_INCLUDE_DIR})
154149
set(Boost_LIBRARY_DIRS ${Boost_LIBRARY_DIR})
155150
if(CMAKE_SYSTEM_NAME MATCHES "Linux")
156151
list(APPEND Boost_LIBRARIES rt)
157152
endif()
158-
endif(BUILD_CUSTOM_BOOST)
153+
endif()
154+
159155
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
156+
160157
link_directories(${Boost_LIBRARY_DIRS})

cmake/update.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
import os
44
import sys
55
import datetime
6+
import ast
67
from collections import OrderedDict, namedtuple
78

89
# we do not use the nicer sys.version_info.major
910
# for compatibility with Python < 2.7
1011
if sys.version_info[0] > 2:
1112
from io import StringIO
12-
from configparser import RawConfigParser
13+
from configparser import ConfigParser
1314
import urllib.request
1415

1516
class URLopener(urllib.request.FancyURLopener):
@@ -18,7 +19,7 @@ def http_error_default(self, url, fp, errcode, errmsg, headers):
1819
sys.exit(-1)
1920
else:
2021
from StringIO import StringIO
21-
from ConfigParser import RawConfigParser
22+
from ConfigParser import ConfigParser
2223
import urllib
2324

2425
class URLopener(urllib.FancyURLopener):
@@ -231,15 +232,15 @@ def gen_cmakelists(project_name, min_cmake_version, relative_path, modules):
231232
# ------------------------------------------------------------------------------
232233

233234

234-
def prepend_or_set(config, section, option, value):
235+
def prepend_or_set(config, section, option, value, defaults):
235236
"""
236237
If option is already set, then value is prepended.
237238
If option is not set, then it is created and set to value.
238239
This is used to prepend options with values which come from the module documentation.
239240
"""
240241
if value:
241242
if config.has_option(section, option):
242-
value += '\n%s' % config.get(section, option)
243+
value += '\n%s' % config.get(section, option, 0, defaults)
243244
config.set(section, option, value)
244245
return config
245246

@@ -276,22 +277,33 @@ def fetch_modules(config, relative_path):
276277
dst = os.path.join(download_directory, 'autocmake_%s' % module_name)
277278
fetch_url(src, dst)
278279
file_name = dst
280+
fetch_dst_directory = download_directory
279281
else:
280282
if os.path.exists(src):
281283
path = os.path.dirname(src)
282284
name = module_name
283285
file_name = src
286+
fetch_dst_directory = path
284287
else:
285288
sys.stderr.write("ERROR: %s does not exist\n" % src)
286289
sys.exit(-1)
287290

291+
if config.has_option(section, 'override'):
292+
defaults = ast.literal_eval(config.get(section, 'override'))
293+
else:
294+
defaults = {}
295+
288296
# we infer config from the module documentation
289297
with open(file_name, 'r') as f:
290-
config_docopt, config_define, config_export, config_fetch = parse_cmake_module(f.read())
291-
config = prepend_or_set(config, section, 'docopt', config_docopt)
292-
config = prepend_or_set(config, section, 'define', config_define)
293-
config = prepend_or_set(config, section, 'export', config_export)
294-
config = prepend_or_set(config, section, 'fetch', config_fetch)
298+
config_docopt, config_define, config_export, config_fetch = parse_cmake_module(f.read(), defaults)
299+
config = prepend_or_set(config, section, 'docopt', config_docopt, defaults)
300+
config = prepend_or_set(config, section, 'define', config_define, defaults)
301+
config = prepend_or_set(config, section, 'export', config_export, defaults)
302+
if config_fetch:
303+
for src in config_fetch.split('\n'):
304+
dst = os.path.join(fetch_dst_directory, os.path.basename(src))
305+
fetch_url(src, dst)
306+
295307
modules.append(Module(path=path, name=name))
296308
i += 1
297309
print_progress_bar(
@@ -301,6 +313,8 @@ def fetch_modules(config, relative_path):
301313
width=30
302314
)
303315
if config.has_option(section, 'fetch'):
316+
# when we fetch directly from autocmake.cfg
317+
# we download into downloaded/
304318
for src in config.get(section, 'fetch').split('\n'):
305319
dst = os.path.join(download_directory, os.path.basename(src))
306320
fetch_url(src, dst)
@@ -369,7 +383,7 @@ def main(argv):
369383

370384
# read config file
371385
print('- parsing autocmake.cfg')
372-
config = RawConfigParser(dict_type=OrderedDict)
386+
config = ConfigParser(dict_type=OrderedDict)
373387
config.read('autocmake.cfg')
374388

375389
if not config.has_option('project', 'name'):
@@ -417,7 +431,7 @@ def make_executable(path):
417431
# ------------------------------------------------------------------------------
418432

419433

420-
def parse_cmake_module(s_in):
434+
def parse_cmake_module(s_in, defaults={}):
421435

422436
config_docopt = None
423437
config_define = None
@@ -448,18 +462,18 @@ def parse_cmake_module(s_in):
448462
autocmake_entry = '[foo]\n' + autocmake_entry
449463

450464
buf = StringIO(autocmake_entry)
451-
config = RawConfigParser(dict_type=OrderedDict)
465+
config = ConfigParser(dict_type=OrderedDict)
452466
config.readfp(buf)
453467

454468
for section in config.sections():
455469
if config.has_option(section, 'docopt'):
456-
config_docopt = config.get(section, 'docopt')
470+
config_docopt = config.get(section, 'docopt', 0, defaults)
457471
if config.has_option(section, 'define'):
458-
config_define = config.get(section, 'define')
472+
config_define = config.get(section, 'define', 0, defaults)
459473
if config.has_option(section, 'export'):
460-
config_export = config.get(section, 'export')
474+
config_export = config.get(section, 'export', 0, defaults)
461475
if config.has_option(section, 'fetch'):
462-
config_fetch = config.get(section, 'fetch')
476+
config_fetch = config.get(section, 'fetch', 0, defaults)
463477

464478
return config_docopt, config_define, config_export, config_fetch
465479

doc/gfx/bi_operators.png

-4 Bytes
Loading

0 commit comments

Comments
 (0)