clang-tidy can't find the target's public headers

250 views Asked by At

I have a cmake project on Windows which uses JOM as the generator and MSVC 19 as the compiler. Now I'm trying to add clang-tidy checks to some of my targets in this project. Here is part of my code to enable clang-tidy:

    if ( CLANG_TIDY_EXE )
        set( _clang_tidy_checkable_headers_abs_path_list ${_tgt_cmn_ct_PUBLIC_INCLUDE_ABS_PATH_LIST} )
        list( APPEND _clang_tidy_checkable_headers_abs_path_list ${_tgt_cmn_ct_PRIVATE_INCLUDE_ABS_PATH_LIST} )
        #Don't check autogenerated headers
        list( FILTER _clang_tidy_checkable_headers_abs_path_list EXCLUDE REGEX "generated/.+" )

        #Clang-tidy is looking for just the header names!
        foreach ( path IN ITEMS ${_clang_tidy_checkable_headers_abs_path_list} )
            get_filename_component( FILE_NAME ${path} NAME )
            list( APPEND HEADERS ${FILE_NAME} )
        endforeach ()

        #Create a regex containing headers name
        set( HEADER_FILTER_REGEX "" )
        string( JOIN "|" HEADER_FILTER_REGEX ${HEADERS} )
        string( REPLACE "."
            "\\." HEADER_FILTER_REGEX
            ${HEADER_FILTER_REGEX} )

        string( PREPEND HEADER_FILTER_REGEX "(" )
        string( APPEND HEADER_FILTER_REGEX ")" )

        #--extra-arg=/EHsc is to get rid of the `clang-diagnostic-error` warning on Windows regarding disabled exceptions!
        set_target_properties(
            ${IN_TARGET_NAME} PROPERTIES
            CXX_CLANG_TIDY "${DO_CLANG_TIDY};--header-filter=${HEADER_FILTER_REGEX};-p=${CMAKE_BINARY_DIR}/compile_commands.json;--extra-arg=/EHsc"
        )

In the above code I basically created a regex out of the private and public headers that I would check by clang-tidy and passed it to the --header-filter argument. Also as you can see I've provided path to the compile_commands.json file as well. But I'm getting following error once I build a target with clang_tidy enabled:

error: 'project_x/common/loggerWrapper/loggerWrapper.hpp' file not found [clang-diagnostic-error]

Note that this loggerWrapper.hpp is actually one of the files I listed in the regex. The interesting point here is that the above solution works perfectly with Ninja but not with JOM.

Any ideas what might be the problem?

0

There are 0 answers