# ExternalWarningLevel automatically set

**URL:** https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477
**Category:** Code
**Tags:** os:windows, comp:msvc, gen:vs
**Created:** [January 24, 2025, 6:54pm UTC](https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477 "2025-01-24T18:54:31Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nick](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/f9ae1b/32.png) [@nick](https://discourse.cmake.org/u/nick)
#### Post date: [January 24, 2025, 6:54pm UTC](https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477/1 "2025-01-24T18:54:31Z")

</div>

I was investigating why external warnings were turned off in our generated projects. I found out that imported libraries, i.e. `add_library(library_name INTERFACE IMPORTED)`, automatically sets the [SYSTEM](https://cmake.org/cmake/help/v3.31/prop_tgt/SYSTEM.html) property, which in turn has the effect that warnings from e.g. externally included header files are disabled (It sets the `ExternalWarningLevel ` tag in the vcxproj file to `TurnOffAllWarnings`). In some cases I would like these warnings to be enabled, for example for template functions. Unfortunately, many cmake config files contain such `add_library` lines, and there is no easy way to force ‘/external:W4’ for a particular target, setting this in the target compile options does not have an effect.

Is there some way to force it anyway without going through each imported library and setting the SYSTEM property to FALSE? Perhaps some options when calling `configure_package_config_file`?

Btw, here is a minimal example showcasing this behavior:

```auto
project(test LANGUAGES CXX)

set(ALL_FILES
    test.cpp
)

add_executable(test ${ALL_FILES})

add_library(not_a_real_library INTERFACE IMPORTED)
set_target_properties(not_a_real_library PROPERTIES
    INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR}
)

target_link_libraries(test PRIVATE not_a_real_library)

```

If you also set the `SYSTEM` property to `FALSE`, the `ExternalWarningLevel ` tag will not be generated in the vcxproj file.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [January 27, 2025, 9:58am UTC](https://discourse.cmake.org/t/externalwarninglevel-automatically-set/13477/2 "2025-01-27T09:58:57Z")

</div>

I have no direct experience with this, but this should be possible based on docs:

- You can turn off the “imported implies SYSTEM” behaviour for a **consuming** target by setting its [`NO_SYSTEM_FROM_IMPORTED` property](https://cmake.org/cmake/help/latest/prop_tgt/NO_SYSTEM_FROM_IMPORTED.html#no-system-from-imported), which can be pre-initialised by setting `CMAKE_NO_SYSTEM_FROM_IMPORTED` variable.
- If you’re in control of the installation of the imported targets, you can set the [`EXPORT_NO_SYSTEM` property](https://cmake.org/cmake/help/latest/prop_tgt/EXPORT_NO_SYSTEM.html#export-no-system) on them to have them generated with `SYSTEM` set to false.
