v0.13.1
ModulesList.cmake
Go to the documentation of this file.
1#
2
3# Load precompiled headers to the speed-up compilation process.
4include(cmake/PrecompileHeaders.cmake)
5
6# Get user module commit id and pass to cpp for logging
7include(${MoFEM_INSTALL_DIR}/include/cmake/GetGitRevisionSimple.cmake)
8
9# If the basic UMs are already loaded target to um library. Otherwise, build a
10# basic user modules library.
11if(EXTERNAL_MODULES_BUILD)
12
13 find_package(
14 UM REQUIRED HINTS ${MOFEM_DIR} ${PROJECT_BINARY_DIR} $ENV{MOFEM_DIR})
15
16 if(UM_INSTALL_PREFIX)
17 include(
18 ${UM_INSTALL_PREFIX}/lib/basic_finite_elements/users_modules_targets.cmake)
19 else(UM_INSTALL_PREFIX)
20 include(
21 ${MoFEM_INSTALL_DIR}/lib/basic_finite_elements/users_modules_targets.cmake)
22 endif(UM_INSTALL_PREFIX)
23
24else(EXTERNAL_MODULES_BUILD)
25
26 get_git_hash(${PROJECT_SOURCE_DIR} GIT_UM_SHA1)
27 get_git_tag(${PROJECT_SOURCE_DIR} "v${UM_FALLBACK_VERSION}" GIT_VERSION)
28 get_git_version(
29 ${GIT_VERSION} UM_VERSION_MAJOR UM_VERSION_MINOR UM_VERSION_BUILD)
30
31 # Build basic finite element library
32 include(${PROJECT_SOURCE_DIR}/basic_finite_elements/UMBuildLib.cmake)
33 # Find modules in a users modules source directory. If file
34 # InstalledAddModule.cmake is found in the directory, it is recognised that
35 # directory is module and name of directory become module name.
36 file(
37 GLOB_RECURSE INSTLLED_MODULES
38 FOLLOW_SYMLINKS
39 ${PROJECT_SOURCE_DIR}/?*/InstalledAddModule.cmake)
40 # Compile tools
41 add_subdirectory(${PROJECT_SOURCE_DIR}/tools)
42endif(EXTERNAL_MODULES_BUILD)
43
44message(STATUS "MoFEM version ${MoFEM_VERSION}")
45set(UM_VERSON
46 ${UM_VERSION_MAJOR}.${UM_VERSION_MINOR}.${UM_VERSION_BUILD}
47 CACHE STRING "UM version" FORCE)
48message(STATUS "User Module commit id: " ${GIT_UM_SHA1})
49message(STATUS "UM GIT_TAG ${GIT_VERSION}")
50message(STATUS "UM Version v${UM_VERSON}")
51
52add_definitions(-DUM_VERSION_MAJOR="${UM_VERSION_MAJOR}")
53add_definitions(-DUM_VERSION_MINOR="${UM_VERSION_MINOR}")
54add_definitions(-DUM_VERSION_BUILD="${UM_VERSION_BUILD}")
55add_definitions(-DGIT_UM_SHA1_NAME="${GIT_UM_SHA1}")
56
57include(cmake/CheckMoFEMVersion.cmake)
58
59# Find modules in an external directory. If file InstalledAddModule.cmake if
60# found in the directory, it is recognised that director is module and name of
61# directory become module name.
62if(EXTERNAL_MODULE_SOURCE_DIRS)
63 foreach(LOOP_DIR ${EXTERNAL_MODULE_SOURCE_DIRS})
64 message(STATUS "Search module directory: " ${LOOP_DIR})
65 file(
66 GLOB_RECURSE EXTERNAL_INSTLLED_MODULES
67 FOLLOW_SYMLINKS
68 ${LOOP_DIR}/*InstalledAddModule.cmake)
69 message(STATUS "Found: " ${EXTERNAL_INSTLLED_MODULES})
70 set(INSTLLED_MODULES ${INSTLLED_MODULES} ${EXTERNAL_INSTLLED_MODULES})
71 endforeach(LOOP_DIR)
72endif(EXTERNAL_MODULE_SOURCE_DIRS)
73
74# Install modules && git pull for all users modules
75add_custom_target(
76 update_users_modules
77 COMMENT "Update all modules ..." VERBATIM)
78add_custom_target(
79 checkout_develop
80 COMMENT "Checkout develop branch ..." VERBATIM)
81add_custom_target(
82 checkout_master
83 COMMENT "Checkout master branch ..." VERBATIM)
84
85# Recognise that module is installed
86foreach(LOOP_MODULE ${INSTLLED_MODULES})
87 string(REGEX REPLACE
88 "/+InstalledAddModule.cmake" ""
89 MODULE_DIRECTORY ${LOOP_MODULE})
90 string(REGEX REPLACE
91 ".*/+" ""
92 MODULE_NAME ${MODULE_DIRECTORY})
93 string(REGEX REPLACE "-" "_" MODULE_NAME ${MODULE_NAME})
94 string(TOUPPER ${MODULE_NAME} MODULE_NAME)
95 message(STATUS "Add definitions to the compiler command -DWITH_MODULE_${MODULE_NAME}")
96 add_definitions(-DWITH_MODULE_${MODULE_NAME})
97endforeach(LOOP_MODULE)
98
99# Add custom tags for all modules
100foreach(LOOP_MODULE ${INSTLLED_MODULES})
101 # message(STATUS "${LOOP_MODULE}")
102 string(REGEX REPLACE
103 "/+InstalledAddModule.cmake" ""
104 MODULE_DIRECTORY ${LOOP_MODULE})
105 message(STATUS "Add module ... ${MODULE_DIRECTORY}")
106 string(REGEX REPLACE
107 ".*/+" ""
108 MODULE_NAME ${MODULE_DIRECTORY}
109 )
110 if(
111 NOT ${MODULE_NAME} MATCHES "basic_finite_elements"
112 AND
113 NOT ${MODULE_NAME} MATCHES "tutorials")
114 #message(STATUS "Add custom targets for ${MODULE_NAME}")
115 add_custom_target(
116 update_${MODULE_NAME}
117 COMMAND ${GIT_EXECUTABLE} pull
118 WORKING_DIRECTORY ${MODULE_DIRECTORY}
119 COMMENT "Update module ... ${MODULE_NAME}" VERBATIM)
120 add_dependencies(update_users_modules update_${MODULE_NAME})
121 add_custom_target(
122 checkout_develop_${MODULE_NAME}
123 COMMAND ${GIT_EXECUTABLE} checkout develop
124 WORKING_DIRECTORY ${MODULE_DIRECTORY}
125 COMMENT "Checkout develop baranch for module ${MODULE_NAME}" VERBATIM)
126 add_dependencies(checkout_develop checkout_develop_${MODULE_NAME})
127 add_custom_target(
128 checkout_master_${MODULE_NAME}
129 COMMAND ${GIT_EXECUTABLE} checkout master
130 WORKING_DIRECTORY ${MODULE_DIRECTORY}
131 COMMENT "Checkout master baranch for module ${MODULE_NAME}" VERBATIM)
132 add_dependencies(checkout_master checkout_master_${MODULE_NAME})
133 endif(
134 NOT ${MODULE_NAME} MATCHES "basic_finite_elements"
135 AND
136 NOT ${MODULE_NAME} MATCHES "tutorials")
137 # include module
138 include(${LOOP_MODULE})
139endforeach(LOOP_MODULE)
140
141if(NOT EXTERNAL_MODULES_BUILD)
142
143 # Generate config files
144 configure_file(
145 ${PROJECT_SOURCE_DIR}/UMConfig-version.cmake.in
146 ${PROJECT_BINARY_DIR}/UMConfig-version.cmake)
147 configure_file(
148 ${PROJECT_SOURCE_DIR}/UMConfig.cmake.in
149 ${PROJECT_BINARY_DIR}/UMConfig.cmake)
150 # Install project files
151 install(
152 FILES ${PROJECT_BINARY_DIR}/UMConfig.cmake
153 DESTINATION ${CMAKE_INSTALL_PREFIX})
154 install(
155 FILES ${PROJECT_BINARY_DIR}/UMConfig-version.cmake
156 DESTINATION ${CMAKE_INSTALL_PREFIX})
157
158endif(NOT EXTERNAL_MODULES_BUILD)