1

I'm trying to disable -use_fast_math for a single .cu file in my project but I'm having no luck in my cmake file.

-use_fast_math is the whole project default, set via

SET(CMAKE_CUDA_FLAGS_RELEASE "-O3 -use_fast_math")

but I can't figure out how to not set -use_fast_math for subsequent individual files. I have seen

set_source_files_properties(${slow_math_files}  PROPERTIES COMPILE_FLAGS "-use_fast_math=false " )

but of course -use_fast_math doesn't take a parameter, and I can't find a way to remove a cuda flag. Also I'm uncertain if the above method sets the correct cuda flag correctly too.

Any advice?

Biggy Smith
  • 910
  • 7
  • 14
  • Does this answer your question? [CMake - remove a compile flag for a single translation unit](https://stackoverflow.com/questions/28344564/cmake-remove-a-compile-flag-for-a-single-translation-unit) – starball Mar 16 '23 at 01:29
  • doesn't seem to work for cuda flags, even when I substitute CMAKE_CUDA_FLAGS_RELEASE for CMAKE_CXX_FLAGS. Think I'm missing something cuda specific – Biggy Smith Mar 16 '23 at 01:45
  • 1
    Related: once https://gitlab.kitware.com/cmake/cmake/-/issues/21986 happens, you can set target compile options that exclude specific source files. – starball Mar 16 '23 at 02:04
  • 2
    This may not be what you want to hear, but to me it seems that you should just not have the flag in the defaults. This is exactly the reason why all modern CMake resources tell you to specify e.g. options at target level. – paleonix Mar 16 '23 at 02:29
  • @paleonix I can remove the default flag and set it per target, but that doesn't help in changing that setting for an individual file. I don't really want to create a whole new project just for one file either. – Biggy Smith Mar 16 '23 at 12:16
  • You can have e.g. an object file as a target. It does not need to be the final executable or library. – paleonix Mar 16 '23 at 23:35
  • really? [here](https://cmake.org/cmake/help/latest/command/target_compile_options.html) it says "These options are used when compiling the given , which must have been created by a command such as add_executable() or add_library()" – Biggy Smith Mar 17 '23 at 00:40
  • You still use `add_library`, see [here](https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries) – paleonix Mar 17 '23 at 02:33

0 Answers0