v0.9.1
ModulesList.cmake
Go to the documentation of this file.
1 # MoFEM is free software: you can redistribute it and/or modify it under
2 # the terms of the GNU Lesser General Public License as published by the
3 # Free Software Foundation, either version 3 of the License, or (at your
4 # option) any later version.
5 #
6 # MoFEM is distributed in the hope that it will be useful, but WITHOUT
7 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
9 # License for more details.
10 #
11 # You should have received a copy of the GNU Lesser General Public
12 # License along with MoFEM. If not, see <http://www.gnu.org/licenses/>
13 
14 # Load precompile headers to the speed-up compilation process.
15 include(cmake/PrecompileHeaders.cmake)
16 
17 # Get user module commit id and pass to cpp for logging
18 include(cmake/GetGitRevisionSimple.cmake)
19 
20 # If the basic UMs are already loaded target to um library. Otherwise, build a
21 # basic user modules library.
22 if(EXTERNAL_MODULES_BUILD)
23 
24  find_package(
25  UM REQUIRED HINTS ${MOFEM_DIR} ${PROJECT_BINARY_DIR} $ENV{MOFEM_DIR})
26 
27  if(UM_INSTALL_BREFIX)
28  include(
29  ${UM_INSTALL_BREFIX}/lib/basic_finite_elements/users_modules_targets.cmake)
30  else(UM_INSTALL_BREFIX)
31  include(
32  ${MoFEM_INSTALL_DIR}/lib/basic_finite_elements/users_modules_targets.cmake)
33  endif(UM_INSTALL_BREFIX)
34 
35 else(EXTERNAL_MODULES_BUILD)
36 
37  get_git_hash(${PROJECT_SOURCE_DIR} GIT_UM_SHA1)
38  get_git_tag(${PROJECT_SOURCE_DIR} "v${UM_FALLBACK_VERSION}" GIT_VERSION)
39  get_git_version(
40  ${GIT_VERSION} UM_VERSION_MAJOR UM_VERSION_MINOR UM_VERSION_BUILD)
41 
42  # Build basic finite element library
43  include(${PROJECT_SOURCE_DIR}/basic_finite_elements/UMBuildLib.cmake)
44  # Download some known modules (Obsolete). It is used to resting on the
45  # developemnt server to automatically clone some modules from git repsitort
46  # to root source directory.
47  include(cmake/WithModules.cmake)
48  # Find modules in a users modules source directory. If file
49  # InstalledAddModule.cmake if found in the directory, it is recognised that
50  # director is module and name of directory become module name.
51  file(
52  GLOB_RECURSE INSTLLED_MODULES
53  FOLLOW_SYMLINKS
54  ${PROJECT_SOURCE_DIR}/?*/InstalledAddModule.cmake)
55  # Compile tools
56  add_subdirectory(${PROJECT_SOURCE_DIR}/tools)
57 endif(EXTERNAL_MODULES_BUILD)
58 
59 message(STATUS "MoFEM version ${MoFEM_VERSION}")
60 set(UM_VERSON
61  ${UM_VERSION_MAJOR}.${UM_VERSION_MINOR}.${UM_VERSION_BUILD})
62 message(STATUS "User Module commit id: " ${GIT_UM_SHA1})
63 message(STATUS "UM GIT_TAG ${GIT_VERSION}")
64 message(STATUS "UM Version v${UM_VERSON}")
65 
66 add_definitions(-DUM_VERSION_MAJOR="${UM_VERSION_MAJOR}")
67 add_definitions(-DUM_VERSION_MINOR="${UM_VERSION_MINOR}")
68 add_definitions(-DUM_VERSION_BUILD="${UM_VERSION_BUILD}")
69 add_definitions(-DGIT_UM_SHA1_NAME="${GIT_UM_SHA1}")
70 
71 include(cmake/CheckMoFEMVersion.cmake)
72 
73 # Find modules in an external directory. If file InstalledAddModule.cmake if
74 # found in the directory, it is recognised that director is module and name of
75 # directory become module name.
76 if(EXTERNAL_MODULE_SOURCE_DIRS)
77  foreach(LOOP_DIR ${EXTERNAL_MODULE_SOURCE_DIRS})
78  message(STATUS "Search module directory: " ${LOOP_DIR})
79  file(
80  GLOB_RECURSE EXTERNAL_INSTLLED_MODULES
81  FOLLOW_SYMLINKS
82  ${LOOP_DIR}/*InstalledAddModule.cmake)
83  message(STATUS "Found: " ${EXTERNAL_INSTLLED_MODULES})
84  set(INSTLLED_MODULES ${INSTLLED_MODULES} ${EXTERNAL_INSTLLED_MODULES})
85  endforeach(LOOP_DIR)
86 endif(EXTERNAL_MODULE_SOURCE_DIRS)
87 
88 # Install modules && git pull for all users modules
89 add_custom_target(
90  update_users_modules
91  COMMENT "Update all modules ..." VERBATIM)
92 add_custom_target(
93  checkout_CDashTesting
94  COMMENT "Checkout CDashTesting branch ..." VERBATIM)
95 add_custom_target(
96  checkout_develop
97  COMMENT "Checkout develop branch ..." VERBATIM)
98 add_custom_target(
99  checkout_master
100  COMMENT "Checkout master branch ..." VERBATIM)
101 
102 # Recognise that module is installed
103 foreach(LOOP_MODULE ${INSTLLED_MODULES})
104  string(REGEX REPLACE
105  "/+InstalledAddModule.cmake" ""
106  MODULE_DIRECTORY ${LOOP_MODULE})
107  string(REGEX REPLACE
108  ".*/+" ""
109  MODULE_NAME ${MODULE_DIRECTORY})
110  string(TOUPPER ${MODULE_NAME} MODULE_NAME)
111  message(STATUS "Add definitions to the compiler command -DWITH_MODULE_${MODULE_NAME}")
112  add_definitions(-DWITH_MODULE_${MODULE_NAME})
113 endforeach(LOOP_MODULE)
114 
115 # Add custom tags for all modules
116 foreach(LOOP_MODULE ${INSTLLED_MODULES})
117  # message(STATUS "${LOOP_MODULE}")
118  string(REGEX REPLACE
119  "/+InstalledAddModule.cmake" ""
120  MODULE_DIRECTORY ${LOOP_MODULE})
121  message(STATUS "Add module ... ${MODULE_DIRECTORY}")
122  string(REGEX REPLACE
123  ".*/+" ""
124  MODULE_NAME ${MODULE_DIRECTORY}
125  )
126  message(STATUS "Add custom targets for ${MODULE_NAME}")
127  add_custom_target(
128  update_${MODULE_NAME}
129  COMMAND ${GIT_EXECUTABLE} pull
130  WORKING_DIRECTORY ${MODULE_DIRECTORY}
131  COMMENT "Update module ... ${MODULE_NAME}" VERBATIM)
132  add_dependencies(update_users_modules update_${MODULE_NAME})
133  add_custom_target(
134  checkout_CDashTesting_${MODULE_NAME}
135  COMMAND ${GIT_EXECUTABLE} checkout CDashTesting
136  WORKING_DIRECTORY ${MODULE_DIRECTORY}
137  COMMENT "Checkout CDashTesting baranch for module ${MODULE_NAME}" VERBATIM)
138  add_dependencies(checkout_CDashTesting checkout_CDashTesting_${MODULE_NAME})
139  add_custom_target(
140  checkout_develop_${MODULE_NAME}
141  COMMAND ${GIT_EXECUTABLE} checkout develop
142  WORKING_DIRECTORY ${MODULE_DIRECTORY}
143  COMMENT "Checkout develop baranch for module ${MODULE_NAME}" VERBATIM)
144  add_dependencies(checkout_develop checkout_develop_${MODULE_NAME})
145  add_custom_target(
146  checkout_master_${MODULE_NAME}
147  COMMAND ${GIT_EXECUTABLE} checkout master
148  WORKING_DIRECTORY ${MODULE_DIRECTORY}
149  COMMENT "Checkout master baranch for module ${MODULE_NAME}" VERBATIM)
150  add_dependencies(checkout_master checkout_master_${MODULE_NAME})
151  # include module
152  include(${LOOP_MODULE})
153 endforeach(LOOP_MODULE)
154 
155 if(NOT EXTERNAL_MODULES_BUILD)
156 
157  # Generate config files
158  configure_file(
159  ${PROJECT_SOURCE_DIR}/UMConfig-version.cmake.in
160  ${PROJECT_BINARY_DIR}/UMConfig-version.cmake)
161  configure_file(
162  ${PROJECT_SOURCE_DIR}/UMConfig.cmake.in
163  ${PROJECT_BINARY_DIR}/UMConfig.cmake)
164  # Install project files
165  install(
166  FILES ${PROJECT_BINARY_DIR}/UMConfig.cmake
167  DESTINATION ${CMAKE_INSTALL_PREFIX})
168  install(
169  FILES ${PROJECT_BINARY_DIR}/UMConfig-version.cmake
170  DESTINATION ${CMAKE_INSTALL_PREFIX})
171 
172 endif(NOT EXTERNAL_MODULES_BUILD)