Handling header files dependencies with cmake

后端 未结 4 589
萌比男神i
萌比男神i 2020-11-28 22:34

I am using CMake on a small C++ project and so far it works great... with one twist :x

When I change a header file, it typically requires recompiling a number of sou

4条回答
  •  臣服心动
    2020-11-28 23:34

    I just hit the same issue. After changing paths in include_directories() from absolute to relative it added appropriate dependencies.

    Looks like CMake tries to guess which headers are system and which are project related. I suspect that directories that starts with / passed as -isystem /some/path and thus are not presented in generated dependencies.

    If you can't replace ${FOO_SOURCE_DIR} with relative path you can try to calculate relative path using appropriate CMake functions. I.e.:

    file(RELATIVE_PATH FOO_SOURCE_REL_DIR
         ${CMAKE_CURRENT_SOURCE_DIR}
         ${FOO_SOURCE_DIR}/.)
    include_directories(${FOO_SOURCE_REL_DIR}/include)
    

提交回复
热议问题