# CMake toolchain file ignores setting flag CMAKE\_CXX\_COMPILE\_OPTIONS\_PIE

**URL:** <https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055>\
**Category:** Code\
**Created:** [November 25, 2024, 12:18pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055 "2024-11-25T12:18:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Acki](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@Acki](https://discourse.cmake.org/u/Acki)\
**Post date:** [November 25, 2024, 12:18pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055/1 "2024-11-25T12:18:36Z")

</div>

In the toolchain I am trying to set the compile setting to `set(CMAKE_CXX_COMPILE_OPTIONS_PIE "-fpie")` small fpie.  
But it has no effect when set in the toolchain.  
Only when I set it in the project itself.

Testcase: [https://godbolt.org/z/vceeq5sez](https://godbolt.org/z/vceeq5sez)

You will see the verbose output the flag “-fPIE”, instead in the toolchain file I set it to: “-fpie”  
In the project you can uncomment “# set(CMAKE\_CXX\_COMPILE\_OPTIONS\_PIE “-fpie”)”  
then it will work.  
Is this a bug?

---

<div class="post-metadata">

**Author:** ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)\
**Post date:** [November 25, 2024, 2:52pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055/2 "2024-11-25T14:52:12Z")

</div>

Enable the trace output and see what sets it. I doubt that setting this is valid in a toolchain file. The project() calls evaluates the compiler afterwards and then this is set to the correct value by compiler.

According to gcc documentation, -fPIE always works while -fpie may not work on some architectures. Why do you want the latter?

---

<div class="post-metadata">

**Author:** ![Acki](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/eada6e/32.png) [@Acki](https://discourse.cmake.org/u/Acki)\
**Post date:** [November 25, 2024, 4:31pm UTC](https://discourse.cmake.org/t/cmake-toolchain-file-ignores-setting-flag-cmake-cxx-compile-options-pie/13055/3 "2024-11-25T16:31:36Z")

</div>

Wen enable the trace output, I only see the  
`toolchain.cmake(1): set(CMAKE_CXX_COMPILE_OPTIONS_PIE -fpie )`  
We are using some QNX compiler which uses some other flags, when compiled in safety mode.

What is so special about the `project()` call? I mean I expect that I can via toolchain all compiler settings and flags, right?
