CMake --build error: file not found

Hi everyone,

I’m working on a Fortran project, using CMake as a build system generator.
To support multiple platforms, I do make use of genexes to control conditional options/definitions:

if (WIN32)
   if (intel-compiler)
      add_compile_options(
         $<$<COMPILE_LANGUAGE:Fortran>:-warn:all>
         $<$<COMPILE_LANGUAGE:Fortran>:-stand:f18>
      )
   endif()
else()
   if (intel-compiler)
      add_compile_options(
         $<$<COMPILE_LANGUAGE:Fortran>:-warn all>
         $<$<COMPILE_LANGUAGE:Fortran>:-stand f18>
      )
   else()
      add_compile_options(
         $<$<COMPILE_LANGUAGE:Fortran>:-Wall>
         $<$<COMPILE_LANGUAGE:Fortran>:-Wimplicit-interface>
         $<$<COMPILE_LANGUAGE:Fortran>:-Wunused-parameter>
         $<$<COMPILE_LANGUAGE:Fortran>:-pedantic>
         $<$<COMPILE_LANGUAGE:Fortran>:-std=f2018>
      )
   endif()
endif()

First, the problem: when compiling using Intel compilers on UNIX OS, I get following error:

Scanning dependencies of target BsaLib
[  3%] Building Fortran object src/CMakeFiles/BsaLib.dir/BsaLib.F90.o
ifort: error #10236: File not found:  '$<1:-warn'
ifort: error #10236: File not found:  'all>'
ifort: command line warning #10006: ignoring unknown option '-assume nocc_omp'
ifort: command line warning #10006: ignoring unknown option '-qparallel'
gmake[2]: *** [src/CMakeFiles/BsaLib.dir/build.make:75: src/CMakeFiles/BsaLib.dir/BsaLib.F90.o] Error 1
gmake[2]: *** Deleting file 'src/CMakeFiles/BsaLib.dir/BsaLib.F90.o'
gmake[1]: *** [CMakeFiles/Makefile2:116: src/CMakeFiles/BsaLib.dir/all] Error 2
gmake: *** [Makefile:91: all] Error 2

Looks like the compile options are not correctly passed (if I disable them all, compiles and run fine). Any suggestion on the source of the problem?

Then, I would realy appreciate if experts might suggest a better, more sustainable approach to do such thing of supporting different platforms.

Thanks everybody!

Cannot have space in genex. Put a semicolon between warn;all

1 Like

@scivision thanks for the remark! I did not think about the whitespace issue.

I found out that with the semicolon ;, I also needed to quote the whole genex expression:

add_compile_options(
         "$<$<COMPILE_LANGUAGE:Fortran>:-warn;all>"
         "$<$<COMPILE_LANGUAGE:Fortran>:-stand;f18>"
)

Without quoting, apparently the compiler complains about:

ifort: command line warning #10006: ignoring unknown option '-warn all'
ifort: command line warning #10006: ignoring unknown option '-stand f18'

but those are indeed valid flags.

I wonder why is that, since from the docs, quoting should fix trhe spacing issue, but here apparently both quoting and ; in place of the space are needed for it to work.

EDIT: ok, thinking about it, maybe only quoting the genex makes CMake to ' single quote ' the expression containing spaces, which is indeed invalid option because of the quotes.

Yes I forgot to say quote and semicolon

If you use C_BOOL between C or C++ and Fortran with Intel compiler you will need

"$<$<AND:$<COMPILE_LANGUAGE:Fortran>,$<NOT:$<BOOL:${WIN32}>>>:-fpscomp;logicals>"
2 Likes