Skip to content
Snippets Groups Projects

Changed the condition to add extra targets regarding formatting in cmake

Merged Pradipta Samanta requested to merge k202170-fix-cmake into master
1 file
+ 52
49
Compare changes
  • Side-by-side
  • Inline
+ 52
49
@@ -56,52 +56,55 @@ install(
include("${PROJECT_SOURCE_DIR}/cmake/list_sources.cmake")
# Collect source files of the project:
list_sources(format_sources)
# Exclude source files of the external projects:
list(FILTER format_sources EXCLUDE REGEX "/_deps/")
# Exclude the configuration header file, which does not have the GENERATED
# property ON because it is automatically generated at the configure time and
# not at the build time:
list(REMOVE_ITEM format_sources "${CMAKE_CURRENT_BINARY_DIR}/src/config.h")
# Exclude source files (not yet automatically) generated with Ragel:
file(GLOB ragel_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/*.rl")
list(TRANSFORM ragel_sources REPLACE "rl$" "c")
list(REMOVE_ITEM format_sources ${ragel_sources})
# Collect C/C++ source files:
set(c_format_sources "${format_sources}")
list(FILTER c_format_sources INCLUDE REGEX "\.(c|h|cpp|hpp)$")
add_custom_target(format-c
COMMAND
clang-format
--style=file
-i
${c_format_sources}
)
# Collect Fortran source files:
set(fortran_format_sources "${format_sources}")
list(FILTER fortran_format_sources INCLUDE REGEX "\.(f|F|f90|F90)$")
add_custom_target(format-fortran
COMMAND
# We do not use a config file but specify the formatting arguments on the
# command line because the feature requires an extra Python package and
# does not work for certain arguments even in the latest release
# (e.g., see https://github.com/pseewald/fprettify/issues/94):
fprettify
--case 2 2 2 1
--indent 2
--whitespace 2
--strip-comments
${fortran_format_sources}
)
add_custom_target(format
DEPENDS
format-c
format-fortran
)
# The following targets are only added if this is a parent project
if("${CMAKE_PROJECT_NAME}" STREQUAL "${PROJECT_NAME}")
# Collect source files of the project:
list_sources(format_sources)
# Exclude source files of the external projects:
list(FILTER format_sources EXCLUDE REGEX "/_deps/")
# Exclude the configuration header file, which does not have the GENERATED
# property ON because it is automatically generated at the configure time and
# not at the build time:
list(REMOVE_ITEM format_sources "${CMAKE_CURRENT_BINARY_DIR}/src/config.h")
# Exclude source files (not yet automatically) generated with Ragel:
file(GLOB ragel_sources "${CMAKE_CURRENT_SOURCE_DIR}/src/*.rl")
list(TRANSFORM ragel_sources REPLACE "rl$" "c")
list(REMOVE_ITEM format_sources ${ragel_sources})
# Collect C/C++ source files:
set(c_format_sources "${format_sources}")
list(FILTER c_format_sources INCLUDE REGEX "\.(c|h|cpp|hpp)$")
add_custom_target(format-c
COMMAND
clang-format
--style=file
-i
${c_format_sources}
)
# Collect Fortran source files:
set(fortran_format_sources "${format_sources}")
list(FILTER fortran_format_sources INCLUDE REGEX "\.(f|F|f90|F90)$")
add_custom_target(format-fortran
COMMAND
# We do not use a config file but specify the formatting arguments on the
# command line because the feature requires an extra Python package and
# does not work for certain arguments even in the latest release
# (e.g., see https://github.com/pseewald/fprettify/issues/94):
fprettify
--case 2 2 2 1
--indent 2
--whitespace 2
--strip-comments
${fortran_format_sources}
)
add_custom_target(format
DEPENDS
format-c
format-fortran
)
endif()
Loading