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.

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

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"
)

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

I get

/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'

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:

set_source_files_properties(test.cpp PROPERTIES
    COMPILE_OPTIONS "-Xarch_x86_64;-mavx"
)
1 Like