v0.14.0
ModulesList.cmake
Go to the documentation of this file.
1 # Load precompiled headers to the speed-up compilation process.
2 include(cmake/PrecompileHeaders.cmake)
3 
4 # Include tutorials build helper functions
5 include(cmake/Tutorials.cmake)
6 
7 # Get user module commit id and pass to cpp for logging
8 include(${MoFEM_INSTALL_DIR}/include/cmake/GetGitRevisionSimple.cmake)
9 
10 # If the basic UMs are already loaded target to um library. Otherwise, build a
11 # basic user modules library.
12 if(EXTERNAL_MODULES_BUILD)
13 
14  find_package(
15  UM REQUIRED HINTS ${MOFEM_DIR} ${PROJECT_BINARY_DIR} $ENV{MOFEM_DIR})
16 
17 
18  #FIXME: check if users_modules_targets.cmake, and include only if it does
19 
20  if(UM_INSTALL_PREFIX)
21  include(
22  ${UM_INSTALL_PREFIX}/lib/basic_finite_elements/users_modules_targets.cmake)
23  else(UM_INSTALL_PREFIX)
24  include(
25  ${MoFEM_INSTALL_DIR}/lib/basic_finite_elements/users_modules_targets.cmake)
26  endif(UM_INSTALL_PREFIX)
27 
28 else(EXTERNAL_MODULES_BUILD)
29 
30  get_git_hash(${PROJECT_SOURCE_DIR} GIT_UM_SHA1)
31  get_git_tag(${PROJECT_SOURCE_DIR} "v${UM_FALLBACK_VERSION}" GIT_VERSION)
32  get_git_version(
33  ${GIT_VERSION} UM_VERSION_MAJOR UM_VERSION_MINOR UM_VERSION_BUILD)
34 
35  # Find modules in a users modules source directory. If file
36  # InstalledAddModule.cmake is found in the directory, it is recognised that
37  # directory is module and name of directory become module name.
38  file(
39  GLOB_RECURSE INSTLLED_MODULES
40  FOLLOW_SYMLINKS
41  ${PROJECT_SOURCE_DIR}/?*/InstalledAddModule.cmake)
42 endif(EXTERNAL_MODULES_BUILD)
43 
44 message(STATUS "MoFEM version ${MoFEM_VERSION}")
45 set(UM_VERSON
46  ${UM_VERSION_MAJOR}.${UM_VERSION_MINOR}.${UM_VERSION_BUILD}
47  CACHE STRING "UM version" FORCE)
48 message(STATUS "User Module commit id: " ${GIT_UM_SHA1})
49 message(STATUS "UM GIT_TAG ${GIT_VERSION}")
50 message(STATUS "UM Version v${UM_VERSON}")
51 
52 add_definitions(-DUM_VERSION_MAJOR="${UM_VERSION_MAJOR}")
53 add_definitions(-DUM_VERSION_MINOR="${UM_VERSION_MINOR}")
54 add_definitions(-DUM_VERSION_BUILD="${UM_VERSION_BUILD}")
55 add_definitions(-DGIT_UM_SHA1_NAME="${GIT_UM_SHA1}")
56 
57 include(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.
62 if(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)
72 endif(EXTERNAL_MODULE_SOURCE_DIRS)
73 
74 # Install modules && git pull for all users modules
75 add_custom_target(
76  update_users_modules
77  COMMENT "Update all modules ..." VERBATIM)
78 add_custom_target(
79  checkout_develop
80  COMMENT "Checkout develop branch ..." VERBATIM)
81 add_custom_target(
82  checkout_master
83  COMMENT "Checkout master branch ..." VERBATIM)
84 
85 # Recognise that module is installed
86 foreach(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})
97 endforeach(LOOP_MODULE)
98 
99 # Add custom tags for all modules
100 foreach(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  #message(STATUS "Add custom targets for ${MODULE_NAME}")
113  add_custom_target(
114  update_${MODULE_NAME}
115  COMMAND ${GIT_EXECUTABLE} pull
116  WORKING_DIRECTORY ${MODULE_DIRECTORY}
117  COMMENT "Update module ... ${MODULE_NAME}" VERBATIM)
118  add_dependencies(update_users_modules update_${MODULE_NAME})
119  add_custom_target(
120  checkout_develop_${MODULE_NAME}
121  COMMAND ${GIT_EXECUTABLE} checkout develop
122  WORKING_DIRECTORY ${MODULE_DIRECTORY}
123  COMMENT "Checkout develop baranch for module ${MODULE_NAME}" VERBATIM)
124  add_dependencies(checkout_develop checkout_develop_${MODULE_NAME})
125  add_custom_target(
126  checkout_master_${MODULE_NAME}
127  COMMAND ${GIT_EXECUTABLE} checkout master
128  WORKING_DIRECTORY ${MODULE_DIRECTORY}
129  COMMENT "Checkout master baranch for module ${MODULE_NAME}" VERBATIM)
130  add_dependencies(checkout_master checkout_master_${MODULE_NAME})
131  endif(
132  NOT ${MODULE_NAME} MATCHES "basic_finite_elements")
133  # include module
134  include(${LOOP_MODULE})
135 endforeach(LOOP_MODULE)
136 
137 if(NOT EXTERNAL_MODULES_BUILD)
138 
139  # Generate config files
140  configure_file(
141  ${PROJECT_SOURCE_DIR}/UMConfig-version.cmake.in
142  ${PROJECT_BINARY_DIR}/UMConfig-version.cmake)
143  configure_file(
144  ${PROJECT_SOURCE_DIR}/UMConfig.cmake.in
145  ${PROJECT_BINARY_DIR}/UMConfig.cmake)
146  # Install project files
147  install(
148  FILES ${PROJECT_BINARY_DIR}/UMConfig.cmake
149  DESTINATION ${CMAKE_INSTALL_PREFIX})
150  install(
151  FILES ${PROJECT_BINARY_DIR}/UMConfig-version.cmake
152  DESTINATION ${CMAKE_INSTALL_PREFIX})
153 
154 endif(NOT EXTERNAL_MODULES_BUILD)