v0.10.0
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  CACHE STRING "UM version" FORCE)
63 message(STATUS "User Module commit id: " ${GIT_UM_SHA1})
64 message(STATUS "UM GIT_TAG ${GIT_VERSION}")
65 message(STATUS "UM Version v${UM_VERSON}")
66 
67 add_definitions(-DUM_VERSION_MAJOR="${UM_VERSION_MAJOR}")
68 add_definitions(-DUM_VERSION_MINOR="${UM_VERSION_MINOR}")
69 add_definitions(-DUM_VERSION_BUILD="${UM_VERSION_BUILD}")
70 add_definitions(-DGIT_UM_SHA1_NAME="${GIT_UM_SHA1}")
71 
72 include(cmake/CheckMoFEMVersion.cmake)
73 
74 # Find modules in an external directory. If file InstalledAddModule.cmake if
75 # found in the directory, it is recognised that director is module and name of
76 # directory become module name.
77 if(EXTERNAL_MODULE_SOURCE_DIRS)
78  foreach(LOOP_DIR ${EXTERNAL_MODULE_SOURCE_DIRS})
79  message(STATUS "Search module directory: " ${LOOP_DIR})
80  file(
81  GLOB_RECURSE EXTERNAL_INSTLLED_MODULES
82  FOLLOW_SYMLINKS
83  ${LOOP_DIR}/*InstalledAddModule.cmake)
84  message(STATUS "Found: " ${EXTERNAL_INSTLLED_MODULES})
85  set(INSTLLED_MODULES ${INSTLLED_MODULES} ${EXTERNAL_INSTLLED_MODULES})
86  endforeach(LOOP_DIR)
87 endif(EXTERNAL_MODULE_SOURCE_DIRS)
88 
89 # Install modules && git pull for all users modules
90 add_custom_target(
91  update_users_modules
92  COMMENT "Update all modules ..." VERBATIM)
93 add_custom_target(
94  checkout_CDashTesting
95  COMMENT "Checkout CDashTesting branch ..." VERBATIM)
96 add_custom_target(
97  checkout_develop
98  COMMENT "Checkout develop branch ..." VERBATIM)
99 add_custom_target(
100  checkout_master
101  COMMENT "Checkout master branch ..." VERBATIM)
102 
103 # Recognise that module is installed
104 foreach(LOOP_MODULE ${INSTLLED_MODULES})
105  string(REGEX REPLACE
106  "/+InstalledAddModule.cmake" ""
107  MODULE_DIRECTORY ${LOOP_MODULE})
108  string(REGEX REPLACE
109  ".*/+" ""
110  MODULE_NAME ${MODULE_DIRECTORY})
111  string(REGEX REPLACE "-" "_" MODULE_NAME ${MODULE_NAME})
112  string(TOUPPER ${MODULE_NAME} MODULE_NAME)
113  message(STATUS "Add definitions to the compiler command -DWITH_MODULE_${MODULE_NAME}")
114  add_definitions(-DWITH_MODULE_${MODULE_NAME})
115 endforeach(LOOP_MODULE)
116 
117 # Add custom tags for all modules
118 foreach(LOOP_MODULE ${INSTLLED_MODULES})
119  # message(STATUS "${LOOP_MODULE}")
120  string(REGEX REPLACE
121  "/+InstalledAddModule.cmake" ""
122  MODULE_DIRECTORY ${LOOP_MODULE})
123  message(STATUS "Add module ... ${MODULE_DIRECTORY}")
124  string(REGEX REPLACE
125  ".*/+" ""
126  MODULE_NAME ${MODULE_DIRECTORY}
127  )
128  message(STATUS "Add custom targets for ${MODULE_NAME}")
129  add_custom_target(
130  update_${MODULE_NAME}
131  COMMAND ${GIT_EXECUTABLE} pull
132  WORKING_DIRECTORY ${MODULE_DIRECTORY}
133  COMMENT "Update module ... ${MODULE_NAME}" VERBATIM)
134  add_dependencies(update_users_modules update_${MODULE_NAME})
135  add_custom_target(
136  checkout_CDashTesting_${MODULE_NAME}
137  COMMAND ${GIT_EXECUTABLE} checkout CDashTesting
138  WORKING_DIRECTORY ${MODULE_DIRECTORY}
139  COMMENT "Checkout CDashTesting baranch for module ${MODULE_NAME}" VERBATIM)
140  add_dependencies(checkout_CDashTesting checkout_CDashTesting_${MODULE_NAME})
141  add_custom_target(
142  checkout_develop_${MODULE_NAME}
143  COMMAND ${GIT_EXECUTABLE} checkout develop
144  WORKING_DIRECTORY ${MODULE_DIRECTORY}
145  COMMENT "Checkout develop baranch for module ${MODULE_NAME}" VERBATIM)
146  add_dependencies(checkout_develop checkout_develop_${MODULE_NAME})
147  add_custom_target(
148  checkout_master_${MODULE_NAME}
149  COMMAND ${GIT_EXECUTABLE} checkout master
150  WORKING_DIRECTORY ${MODULE_DIRECTORY}
151  COMMENT "Checkout master baranch for module ${MODULE_NAME}" VERBATIM)
152  add_dependencies(checkout_master checkout_master_${MODULE_NAME})
153  # include module
154  include(${LOOP_MODULE})
155 endforeach(LOOP_MODULE)
156 
157 if(NOT EXTERNAL_MODULES_BUILD)
158 
159  # Generate config files
160  configure_file(
161  ${PROJECT_SOURCE_DIR}/UMConfig-version.cmake.in
162  ${PROJECT_BINARY_DIR}/UMConfig-version.cmake)
163  configure_file(
164  ${PROJECT_SOURCE_DIR}/UMConfig.cmake.in
165  ${PROJECT_BINARY_DIR}/UMConfig.cmake)
166  # Install project files
167  install(
168  FILES ${PROJECT_BINARY_DIR}/UMConfig.cmake
169  DESTINATION ${CMAKE_INSTALL_PREFIX})
170  install(
171  FILES ${PROJECT_BINARY_DIR}/UMConfig-version.cmake
172  DESTINATION ${CMAKE_INSTALL_PREFIX})
173 
174 endif(NOT EXTERNAL_MODULES_BUILD)