Unwanted quotes in extra compile options for a specific Fortran source

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)

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.

Take time to read the documentation of the COMPILE_OPTIONS source property as well as the set_source_files_properties() command…

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.

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:

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

a minimal working example with Intel oneAPI below.

OP doesn’t need the generator expressions it seems.

@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.

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.