-
Notifications
You must be signed in to change notification settings - Fork 0
/
duneMacroAddModule.cmake
99 lines (85 loc) · 3.68 KB
/
duneMacroAddModule.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
macro(duneMacroAddModule)
macro_parse_arguments(_module "NAME;LOCATION_ARGS" "" ${ARGN})
set(dune_module_configure_options
CC=${CMAKE_C_COMPILER}
CFLAGS=${CMAKE_C_FLAGS}
CXX=${CMAKE_CXX_COMPILER}
CPPFLAGS=${CMAKE_CXX_FLAGS}
)
set(_install_dir )
if(NOT CMAKE_INSTALL_PREFIX)
set(_install_dir ${PROJECT_BINARY_DIR}/DUNE-install)
elseif(IS_ABSOLUTE ${CMAKE_INSTALL_PREFIX})
set(_install_dir ${CMAKE_INSTALL_PREFIX})
else()
set(_install_dir ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_PREFIX})
endif()
list(APPEND dune_module_configure_options --prefix=${_install_dir})
if(NOT DUNE_ENABLE_DOCUMENTATION)
list(APPEND dune_module_configure_options --disable-documentation)
endif()
if(DUNE_USE_BOOST)
list(APPEND dune_module_configure_options --with-boost=${BOOST_ROOT})
endif()
if(DUNE_USE_MPI)
list(APPEND dune_module_configure_options MPICC=${MPI_C_COMPILER} --enable-parallel)
endif()
set(third_party_deps )
foreach(_third_party_lib ${DUNE_THIRD_PARTY_LIBS})
string(TOUPPER "${_third_party_lib}" _third_party_lib_upper)
string(TOLOWER "${_third_party_lib}" _third_party_lib_lower)
list(FIND ${_module_NAME}_SUGGESTS ${_third_party_lib_lower} _found)
if(DUNE_USE_${_third_party_lib_upper} AND _found GREATER -1)
list(APPEND dune_module_configure_options --with-${_third_party_lib_lower}=${${_third_party_lib_upper}_DIR})
list(APPEND third_party_deps ${${_third_party_lib_upper}_DEPENDS})
endif()
endforeach()
# Use --with-<PACKAGE> options for module dependencies
if(${_module_NAME}_DEPENDS)
foreach(_dune_module_dep ${${_module_NAME}_DEPENDS})
list(APPEND dune_module_configure_options
--with-${_dune_module_dep}=${_install_dir}
)
endforeach()
endif()
# Add custom configure options
list(APPEND dune_module_configure_options ${DUNE_MODULE_${_module_NAME}_CONFIGURE_OPTIONS})
# Add compiler flags
if(CMAKE_BUILD_TYPE STREQUAL Release)
list(APPEND dune_module_configure_options
"CXXFLAGS=${DUNE_CMAKE_CXX_FLAGS_RELEASE} ${DUNE_MODULE_${_module_NAME}_CXX_FLAGS_RELEASE}")
elseif(CMAKE_BUILD_TYPE STREQUAL Debug)
list(APPEND dune_module_configure_options
"CXXFLAGS=${DUNE_CMAKE_CXX_FLAGS_DEBUG} ${DUNE_MODULE_${_module_NAME}_CXX_FLAGS_DEBUG}")
endif()
set(${_module_NAME}_CONFIGURE_OPTIONS ${dune_module_configure_options})
set(${_module_NAME}_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/${_module_NAME}-${${_module_NAME}_VERSION}-build)
macro_parse_arguments(_tmp "SOURCE_DIR" "" ${_module_LOCATION_ARGS})
list(GET _tmp_SOURCE_DIR 0 _tmp_SOURCE_DIR)
if(NOT IS_ABSOLUTE "${_tmp_SOURCE_DIR}")
set(_tmp_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/${_tmp_SOURCE_DIR}")
endif()
if(NOT EXISTS "${_tmp_SOURCE_DIR}/configure" AND
NOT DUNE_BOOTSTRAP_FROM_TARBALLS)
set(_module_build_cmds
CONFIGURE_COMMAND cat /dev/null
BUILD_COMMAND cat /dev/null
)
message(WARNING "!!Unconfigured DUNE module [${_module_NAME}]!!\nType make rebuild_cache && make after the initial build to complete the process.\n")
else()
set(_module_build_cmds
CONFIGURE_COMMAND <SOURCE_DIR>/configure --srcdir=<SOURCE_DIR> ${dune_module_configure_options}
BUILD_COMMAND $(MAKE)
)
endif()
ExternalProject_Add(${_module_NAME}
${_module_LOCATION_ARGS}
BINARY_DIR ${_module_NAME}-${${_module_NAME}_VERSION}-build
PREFIX ${_module_NAME}-${${_module_NAME}_VERSION}-cmake
#INSTALL_DIR ${_module_NAME}-${${_module_NAME}_VERSION}-install
INSTALL_DIR ${_install_dir}
${_module_build_cmds}
INSTALL_COMMAND $(MAKE) install
DEPENDS ${third_party_deps} ${${_module_NAME}_DEPENDS}
)
endmacro()