Skip to content

Commit

Permalink
cmake: add functionality to compile only matching solver modules
Browse files Browse the repository at this point in the history
  • Loading branch information
juhanikataja committed Aug 20, 2024
1 parent 859a9de commit e087070
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ SET(WITH_ROCALUTION FALSE CACHE BOOL "Compile with Rocalution library.")

SET(WITH_Zoltan FALSE CACHE BOOL "Link in Zoltan mesh repartitioning library.")

SET(INCLUDE_ELMER_MODULES "" CACHE STRING "Semicolon separated list of solver modules to be compiled. If empty compile all.")

# Let user select if the contiguous attribute is used or not
SET(USE_CONTIGUOUS FALSE CACHE BOOL "Use contiguous attribute")

Expand Down
49 changes: 47 additions & 2 deletions cmake/Modules/AddModules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@
# Adds solver module <name> having sources in "<name>.F90".
# Optionally treat all .F90 files in <subdirectory> as sources.
#
#
# ADD_ELMER_MODULES([SKIP <name_1> <name_2> ... <skip_n>])
# Treats all directories and .F90 files from current directory as input
# for ADD_ELMER_MODULE. Skips those files and directories that equal
# to <skip_m> for some 0<m<n+1.
#
#
# MAKE_SKIP_LIST(INCLUDE name_1;name_2;...;name_n)
# Find all modules similarly as ADD_ELMER_MODULES and remove those modules from the list
# that match name_1, or name_2, or, ..., name_n.
#
# Populates a local variable called SKIP_LIST with the resulting list.
#
# Useful when combined with ADD_ELMER_MODULES(SKIP SKIP_LIST)



MACRO(ADD_ELMER_MODULE BASENAME)
CMAKE_PARSE_ARGUMENTS(_parsedArgs "" "" "SOURCES;DIRECTORY" "${ARGN}")
Expand Down Expand Up @@ -44,9 +56,9 @@ MACRO(ADD_ELMER_MODULES)
FILE(GLOB SRC_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.F90")

FOREACH(FNAME ${SRC_FILES})
LIST(FIND _parsedArgs_SKIP ${FNAME} FILE_INDEX)
GET_FILENAME_COMPONENT(BASENAME ${FNAME} NAME_WE)
LIST(FIND _parsedArgs_SKIP ${BASENAME} FILE_INDEX)
IF(FILE_INDEX EQUAL -1)
GET_FILENAME_COMPONENT(BASENAME ${FNAME} NAME_WE)
IF(NOT BASENAME STREQUAL "")
ADD_ELMER_MODULE(${BASENAME})
ENDIF()
Expand All @@ -69,3 +81,36 @@ MACRO(ADD_ELMER_MODULES)

message(STATUS "Found ${num_modules} modules from ${CMAKE_CURRENT_SOURCE_DIR}")
ENDMACRO()

MACRO(MAKE_SKIP_LIST) # Provide list of modules to be included
CMAKE_PARSE_ARGUMENTS(_parsedArgs "" "" "INCLUDE" "${ARGN}")

FILE(GLOB SRC_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*.F90")

SET(SKIP_LIST "")

FOREACH(FNAME ${SRC_FILES})
GET_FILENAME_COMPONENT(BASENAME ${FNAME} NAME_WE)

IF(NOT ${BASENAME} IN_LIST _parsedArgs_INCLUDE)
LIST(APPEND SKIP_LIST ${BASENAME})
ELSE()
message(STATUS "Including ${BASENAME} module")
ENDIF()
ENDFOREACH()


FILE(GLOB SRC_DIRS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "*")

FOREACH(DIRNAME ${SRC_DIRS})
IF(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${DIRNAME}")
LIST(FIND ARGN ${DIRNAME} DIR_INDEX)
IF(NOT ${DIRNAME} IN_LIST _parsedArgs_INCLUDE)
LIST(APPEND SKIP_LIST ${DIRNAME})
ELSE()
message(STATUS "Including ${DIRNAME} module")
ENDIF()
ENDIF()
ENDFOREACH()

ENDMACRO()
21 changes: 17 additions & 4 deletions fem/src/modules/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,28 @@ INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/fem/src")
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/fhutiter/include")
INCLUDE(AddModules)

ADD_ELMER_MODULES(SKIP contrib)


if(INCLUDE_ELMER_MODULES)
MAKE_SKIP_LIST(INCLUDE ${INCLUDE_ELMER_MODULES})
endif()

LIST(APPEND SKIP_LIST contrib)
ADD_ELMER_MODULES(SKIP ${SKIP_LIST})

IF(WITH_CONTRIB)
ADD_SUBDIRECTORY(contrib)
ENDIF(WITH_CONTRIB)

ADD_DEPENDENCIES(EliminatePeriodic EliminateDirichlet)
ADD_DEPENDENCIES(FourierLoss MagnetoDynamics)
TARGET_LINK_LIBRARIES(EliminatePeriodic EliminateDirichlet)
if(TARGET EliminatePeriodic)
ADD_DEPENDENCIES(EliminatePeriodic EliminateDirichlet)
TARGET_LINK_LIBRARIES(EliminatePeriodic EliminateDirichlet)
endif()

if(TARGET FourierLoss)
ADD_DEPENDENCIES(FourierLoss MagnetoDynamics)
endif()


#IF(HAVE_NETCDF)
# TARGET_LINK_LIBRARIES(SaveGridData ${NETCDF_LIBRARY})
Expand Down

0 comments on commit e087070

Please sign in to comment.