3

NO_SYSTEM_FROM_IMPORTED tells us that IMPORTED targets automagically get -isystem. Does that also hold for targets introduced to the project with FetchContent?

If not (I assume so due to having problems with clang-tidy warnings on fetched targets), what is the best way to get -isystem for such targets?

starball
  • 20,030
  • 7
  • 43
  • 238
  • `FetchContent` provides you the project's sources which you include with `add_subdirectory`. Since the project defines (usually) normal (non-IMPORTED) targets, they doesn't have `SYSTEM` property. "what is the best way to get `-isystem` for such targets?" - Build the project **separately** from your main project. In the main project you may use `find_package` for include the project which is built. That way you will have `IMPORTED` target, which is accompanied with `SYSTEM` include directories. – Tsyvarev Sep 25 '20 at 14:09
  • What you describe sounds like `ExternalProject_add`s ballpark and superbuild scripts. I was under the impression, that `FetchContent` was created to give access to external targets at config time, so at build time it is built like it would be part of your codebase. Now I just want to break that "bonding" up again, and mark those targets as `SYSTEM` includes, but still have one big build. Does that make sense? – Florian Berchtold Sep 29 '20 at 07:24
  • "... at build time it is built like it would be part of your codebase." - Yes, it is correct: a fetched project becomes part of your codebase. "mark those targets as SYSTEM includes" - CMake simply doesn't have such mark. You may try, however, to copy content of property [INTERFACE_INCLUDE_DIRECTORIES](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_INCLUDE_DIRECTORIES.html) to [INTERFACE_SYSTEM_INCLUDE_DIRECTORIES](https://cmake.org/cmake/help/latest/prop_tgt/INTERFACE_SYSTEM_INCLUDE_DIRECTORIES.html) one. This would effectively mark all include directories for target as SYSTEM. – Tsyvarev Sep 29 '20 at 08:19

2 Answers2

8

NO_SYSTEM_FROM_IMPORTED tells us that IMPORTED targets automagically get -isystem. Does that also hold for targets introduced to the project with FetchContent?

No, because targets added by FetchContent are essentially added by add_subdirectory: they become targets to build (instead of just import) in the generated buildystem.

If not (I assume so due to having problems with clang-tidy warnings on fetched targets), what is the best way to get -isystem for such targets?

If you are using CMake 3.25 (cmake_minimum_required(VERSION 3.25)), you can use the SYSTEM argument of FetchContent_Declare, which was added in merge request #7399 by contributor daquexian.

For users of CPM, I have given the CPM authors a heads up about this change here.

There is also the new SYSTEM target property, which was added in merge request #7308 (also by daquexian). If SYSTEM is ON, the INTERFACE_INCLUDE_DIRECTORIES will be treated as system include directories.

If your cmake_minimum_required(VERSION ...) is less than v3.25, then use this other answer.

starball
  • 20,030
  • 7
  • 43
  • 238
5

It is actually really easy (kudos to @Tsyvarev):

include (FetchContent)

set (FETCHCONTENT_QUIET FALSE)

FetchContent_Declare (
  Catch2
  GIT_REPOSITORY https://github.com/catchorg/Catch2.git
  GIT_TAG v2.4.2
  GIT_PROGRESS TRUE
)

FetchContent_MakeAvailable (Catch2)

### here is what makes all include directories -isystem
get_target_property(CATCH2_IID Catch2 INTERFACE_INCLUDE_DIRECTORIES)
set_target_properties(Catch2 PROPERTIES INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${CATCH2_IID}")