Skip to content

Commit 992359f

Browse files
committed
Theory is that the include directories for mpi are not getting properly added due to the compiler wrapper. CMake code here is Claude output and is not suitable for merging as is, but fine for testing the theory.
1 parent f6bc7a8 commit 992359f

1 file changed

Lines changed: 32 additions & 8 deletions

File tree

CMakeLists.txt

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ if(PROJECT_IS_TOP_LEVEL)
3434
message(STATUS "RUN_CLANG_TIDY_EXECUTABLE= ${RUN_CLANG_TIDY_EXECUTABLE}")
3535
message(STATUS "CLANG_TIDY_CONFIG_FILE=${CLANG_TIDY_CONFIG_FILE}")
3636
message(STATUS "CLANG_TIDY_SOURCE_FILTER=${CLANG_TIDY_SOURCE_FILTER}")
37-
38-
add_custom_target(run-clang-tidy
39-
VERBATIM COMMAND ${RUN_CLANG_TIDY_EXECUTABLE}
40-
-clang-tidy-binary ${CLANG_TIDY_EXECUTABLE}
41-
-p ${CMAKE_BINARY_DIR}
42-
-config-file ${CLANG_TIDY_CONFIG_FILE}
43-
-source-filter ${CLANG_TIDY_SOURCE_FILTER}
44-
)
4537
endif()
4638

4739
option(PCMS_ENABLE_SERVER "enable the coupling server implementation" ON)
@@ -82,6 +74,38 @@ endif()
8274

8375
set(MPI_CXX_SKIP_MPICXX ON)
8476
find_package(MPI REQUIRED)
77+
78+
# Create the run-clang-tidy target here (after find_package(MPI)) so we can
79+
# forward any MPI include paths that are missing from compile_commands.json.
80+
# When CMAKE_CXX_COMPILER is an MPI wrapper (e.g. mpicxx), FindMPI may leave
81+
# MPI_CXX_INCLUDE_DIRS empty because the wrapper handles includes implicitly,
82+
# meaning compile_commands.json has no explicit -I flags for mpi.h.
83+
if(PROJECT_IS_TOP_LEVEL)
84+
set(_clang_tidy_extra_args "")
85+
get_target_property(_mpi_cxx_incs MPI::MPI_CXX INTERFACE_INCLUDE_DIRECTORIES)
86+
if(NOT _mpi_cxx_incs)
87+
execute_process(
88+
COMMAND ${MPI_CXX_COMPILER} -show
89+
OUTPUT_VARIABLE _mpi_show
90+
OUTPUT_STRIP_TRAILING_WHITESPACE
91+
ERROR_QUIET)
92+
string(REGEX MATCHALL "-I([^ ]+)" _mpi_inc_flags "${_mpi_show}")
93+
foreach(_flag IN LISTS _mpi_inc_flags)
94+
list(APPEND _clang_tidy_extra_args "-extra-arg=${_flag}")
95+
endforeach()
96+
message(STATUS "clang-tidy MPI extra args: ${_clang_tidy_extra_args}")
97+
endif()
98+
99+
add_custom_target(run-clang-tidy
100+
VERBATIM COMMAND ${RUN_CLANG_TIDY_EXECUTABLE}
101+
-clang-tidy-binary ${CLANG_TIDY_EXECUTABLE}
102+
-p ${CMAKE_BINARY_DIR}
103+
-config-file ${CLANG_TIDY_CONFIG_FILE}
104+
-source-filter ${CLANG_TIDY_SOURCE_FILTER}
105+
${_clang_tidy_extra_args}
106+
)
107+
endif()
108+
85109
message(STATUS "Found redev: ${redev_DIR} (found version ${redev_VERSION})")
86110
if(PCMS_ENABLE_OMEGA_H)
87111
find_package(Omega_h REQUIRED VERSION 10)

0 commit comments

Comments
 (0)