# Unwanted quotes in extra compile options for a specific Fortran source

**URL:** https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778
**Category:** Code
**Created:** [September 26, 2024, 3:40pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778 "2024-09-26T15:40:20Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)
#### Post date: [September 26, 2024, 3:40pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/1 "2024-09-26T15:40:20Z")

</div>

Hi, in my Fortran project I need to add some extra compilation flag for a given source file `cklib.f`

I used the command

`set_source_files_properties(src/cklib.f PROPERTIES COMPILE_OPTIONS "-warn nointerfaces")`

It inserts the extra compilation flag, but between quotes:

`/opt/intel/oneapi/mpi/2021.13/bin/mpiifx -I/usr/local/apps/ciracfd/modules/intel -g -diag-disable:10440 -module modules -fpp -convert big_endian -r8 -fpe0 -O0 -g -traceback -debug full -check all -align -gen-interfaces -warn all,noexternal` **“-warn nointerfaces”** `-c /home/andream/CODES/NEXT/src/cklib.f -o CMakeFiles/NEXT_intel_V_3.8.0.dir/src/cklib.f.`

and the compiler does not recognize it. If I remove the quotes by giving

`set_source_files_properties(src/cklib.f PROPERTIES COMPILE_OPTIONS -warn nointerfaces)`

```auto
CMake Error at CMakeLists.txt:82 (set_source_files_properties):
  set_source_files_properties called with incorrect number of arguments.

```

Hints to include the extra flag **without quotes**? Thank you.

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [September 26, 2024, 3:53pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/2 "2024-09-26T15:53:15Z")

</div>

Take time to read the documentation of the [COMPILE\_OPTIONS](https://cmake.org/cmake/help/latest/prop_sf/COMPILE_OPTIONS.html) source property as well as the [set\_source\_files\_properties()](https://cmake.org/cmake/help/latest/command/set_source_files_properties.html) command…

---

<div class="post-metadata">

### Author: ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)
#### Post date: [September 26, 2024, 5:52pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/3 "2024-09-26T17:52:53Z")

</div>

I have read more times the documentation you suggested and I have found no clues how to do it. Please apologize me, but I am new in this field.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [September 26, 2024, 10:24pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/4 "2024-09-26T22:24:21Z")

</div>

You’re wanting to add two separate items on the command-line, but you need to keep them together. To prevent CMake from de-duplicating the `-warn` part, you need the `SHELL:` prefix. I think the following should give you what you were looking for:

```cmake
set_source_files_properties(src/cklib.f PROPERTIES
    COMPILE_OPTIONS "SHELL:-warn nointerfaces"
)

```

---

<div class="post-metadata">

### Author: ![scivision](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/a87d85/32.png) [@scivision](https://discourse.cmake.org/u/scivision)
#### Post date: [September 27, 2024, 2:59am UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/5 "2024-09-27T02:59:00Z")

</div>

a minimal working example with Intel oneAPI below.

OP doesn’t need the generator expressions it seems.

> <https://gist.github.com/scivision/c613f48d2417cabcb8522627a931dfec>

---

<div class="post-metadata">

### Author: ![artu72](https://discourse.cmake.org/user_avatar/discourse.cmake.org/artu72/32/4929_2.png) [@artu72](https://discourse.cmake.org/u/artu72)
#### Post date: [September 27, 2024, 12:45pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/6 "2024-09-27T12:45:02Z")

</div>

@craig.scott , @scivision Thank you very much. The `:SHELL` prefix however did not produce any effect, since the quotes are always present. However, the compiler now accepts the (quoted) extra option. Perhaps I have misconfigured some command in CMakeList.txt file before and I amended it without realizing.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [September 28, 2024, 1:48am UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/7 "2024-09-28T01:48:54Z")

</div>

Don’t try to force quotes, let CMake handle adding them where needed. The `SHELL:` prefix (note the colon comes _after_ the word `SHELL`) is telling CMake “keep these arguments together and put them on the command line exactly the way I specify them”. This prevents CMake from de-duplicating the individual options, which would otherwise remove the `-warn` because you have another `-warn` option already.

---

<div class="post-metadata">

### Author: ![hjmallon](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hjmallon/32/819_2.png) [@hjmallon](https://discourse.cmake.org/u/hjmallon)
#### Post date: [April 15, 2025, 10:23am UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/8 "2025-04-15T10:23:40Z")

</div>

@craig.scott : Am I doing something wrong here?

```auto
cmake_minimum_required(VERSION 3.10)

project(test)

add_executable(test test.cpp)

set_source_files_properties(test.cpp PROPERTIES
    COMPILE_OPTIONS "SHELL:-Xarch_x86_64 -mavx"
)

```

```auto
int main(int argc, const char* argv[])
{
    return 0;
}

```

I get

```auto
/usr/bin/c++ -arch arm64 "SHELL:-Xarch_x86_64 -mavx" -MD -MT CMakeFiles/test.dir/test.cpp.o -MF CMakeFiles/test.dir/test.cpp.o.d -o CMakeFiles/test.dir/test.cpp.o -o XXX/test/test.cpp
clang++: error: no such file or directory: 'SHELL:-Xarch_x86_64 -mavx'

```

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [April 15, 2025, 2:17pm UTC](https://discourse.cmake.org/t/unwanted-quotes-in-extra-compile-options-for-a-specific-fortran-source/11778/9 "2025-04-15T14:17:53Z")

</div>

I think “SHELL:” is not supported for `COMPILE_OPTIONS` property of the source files. But, because deduplication is not applied to the source compile options, you can specify the options as a `CMake` list:

```cmake
set_source_files_properties(test.cpp PROPERTIES
    COMPILE_OPTIONS "-Xarch_x86_64;-mavx"
)

```
