# How to disable '-pedantic' compiler option for a specific library?

**URL:** https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575
**Category:** Usage
**Created:** [July 16, 2020, 5:14pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575 "2020-07-16T17:14:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [July 16, 2020, 5:14pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/1 "2020-07-16T17:14:30Z")

</div>

For my gcc C++ project, my top-level CMakeLists.txt contains:

add\_compile\_options(-Wall -pedantic)

and it builds multiple libraries using add\_subdirectory() calls.

How can I disable the ‘-pedantic’ flag for one of those libraries by modifying the CMakeLists.txt file of that library?

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [July 17, 2020, 8:56am UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/2 "2020-07-17T08:56:58Z")

</div>

I tried this:

```auto
  string(REPLACE " -pedantic" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
  add_subdirectory(Prototypes/dpdk_test_static_library/dpdk)
  set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")

```

But it didn’t work: -pedantic still appeared in the g++ command line for the library source files.

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [July 17, 2020, 12:36pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/3 "2020-07-17T12:36:40Z")

</div>

The variable `CMAKE_CXX_FLAGS` does not contain the values stored by the property set by `add_compile_options`. You need to modify the property for the targets created downstream in `Prototypes/dpdk_test_static_library/dpdk/CMakeLists.txt`. After the target is created then you can modify `COMPILE_OPTIONS` property for that target. Or you can try to modify the directory property `COMPILE_OPTIONS` before calling `add_subdirectory()`.

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [July 17, 2020, 12:42pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/4 "2020-07-17T12:42:39Z")

</div>

> [@fdk17](#):
>
> After the target is created then you can modify `COMPILE_OPTIONS` property for that target.

Thanks. How would I delete ‘-pedantic’ from COMPILE\_OPTIONS in dpdk/CMakeLists.txt?

---

<div class="post-metadata">

### Author: ![fdk17](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/f/ea666f/32.png) [@fdk17](https://discourse.cmake.org/u/fdk17)
#### Post date: [July 17, 2020, 1:41pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/5 "2020-07-17T13:41:13Z")

</div>

You’ll want to do something like this:

```auto
    # Remove entry
    get_target_property(target_options my_target COMPILE_OPTIONS)
    list(REMOVE_ITEM target_options "-pedantic")
    set_property(TARGET my_target PROPERTY COMPILE_OPTIONS ${target_options})

```

---

<div class="post-metadata">

### Author: ![DavidA](https://discourse.cmake.org/user_avatar/discourse.cmake.org/davida/32/128_2.png) [@DavidA](https://discourse.cmake.org/u/DavidA)
#### Post date: [July 17, 2020, 3:04pm UTC](https://discourse.cmake.org/t/how-to-disable-pedantic-compiler-option-for-a-specific-library/1575/6 "2020-07-17T15:04:51Z")

</div>

Thanks for your help.
