Skip to content

Commit

Permalink
CMake: deal_ii_invoke_autopilot: mild refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
tamiko committed Oct 12, 2024
1 parent 9d0a489 commit a02ee95
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions cmake/macros/macro_deal_ii_invoke_autopilot.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@
#

macro(deal_ii_invoke_autopilot)
message(STATUS "Autopilot invoked")

# Generator specific values:
if(CMAKE_GENERATOR MATCHES "Ninja")
set(_make_command "$ ninja")
else()
set(_make_command " $ make")
endif()
#
# Generate compile_commands.json
#

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)

Expand Down Expand Up @@ -72,9 +70,14 @@ macro(deal_ii_invoke_autopilot)

# Define and set up a compilation target:
add_executable(${TARGET} ${TARGET_SRC})
deal_ii_setup_target(${TARGET})
target_link_libraries(${TARGET} dealii::dealii)

message(STATUS "Autopilot invoked")
# Generator specific values:
if(CMAKE_GENERATOR MATCHES "Ninja")
set(_make_command "$ ninja")
else()
set(_make_command " $ make")
endif()

# Define a custom target to easily run the program:
if(NOT DEFINED TARGET_RUN)
Expand Down Expand Up @@ -102,24 +105,21 @@ macro(deal_ii_invoke_autopilot)
set(_command
${CMAKE_COMMAND} -P ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/run_target.cmake
)

else()

set(_command ${TARGET_RUN})
endif()

if(NOT "${TARGET_RUN}" STREQUAL "")
add_custom_target(run
COMMAND ${_command}
DEPENDS ${TARGET}
COMMENT "Run ${TARGET} with ${CMAKE_BUILD_TYPE} configuration"
COMMENT "Run ${TARGET} with $<$<CONFIG:Release>:Release>$<$<CONFIG:Debug>:Debug> configuration"
)
set(_run_targets
"# ${_make_command} run - to (compile, link and) run the program\n"
)
endif()


#
# Provide a target to sign the generated executable with a Mac OSX
# developer key. This avoids problems with an enabled firewall and MPI
Expand Down Expand Up @@ -184,18 +184,9 @@ macro(deal_ii_invoke_autopilot)
endif()

#
# Only mention release and debug targets if it is actually possible to
# switch between them:
# And another custom target to clean up all files generated by the program:
#

if(${DEAL_II_BUILD_TYPE} MATCHES "DebugRelease")
set(_switch_targets
"# ${_make_command} debug - to switch the build type to 'Debug'
# ${_make_command} release - to switch the build type to 'Release'\n"
)
endif()

# And another custom target to clean up all files generated by the program:
if("${CLEAN_UP_FILES}" STREQUAL "")
set(CLEAN_UP_FILES *.log *.gmv *.gnuplot *.gpl *.eps *.pov *.vtk *.ucd *.d2)
endif()
Expand All @@ -204,7 +195,10 @@ macro(deal_ii_invoke_autopilot)
COMMENT "runclean invoked"
)

#
# Define a distclean target to remove every generated file:
#

add_custom_target(distclean
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target clean
COMMAND ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR} --target runclean
Expand All @@ -215,7 +209,10 @@ macro(deal_ii_invoke_autopilot)
COMMENT "distclean invoked"
)

#
# Define a strip_comments target:
#

find_package(Perl QUIET)
if(PERL_FOUND)
add_custom_target(strip_comments
Expand All @@ -224,8 +221,19 @@ macro(deal_ii_invoke_autopilot)
)
endif()

#
# Construct help message:
#

# Only mention release and debug targets if it is actually possible to
# switch between them:
if(${DEAL_II_BUILD_TYPE} MATCHES "DebugRelease")
set(_switch_targets
"# ${_make_command} debug - to switch the build type to 'Debug'
# ${_make_command} release - to switch the build type to 'Release'\n"
)
endif()

# Print out some usage information to file:
file(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/print_usage.cmake
"message(
\"###
Expand Down

0 comments on commit a02ee95

Please sign in to comment.