How do I add a compiler flag (I want to APPEND it, not overwrite the others) to a single translation unit with cmake?
I tried with
set_source_files_properties(MyFile.cpp PROPERTIES CMAKE_CXX_FLAGS "-msse4.1")
but it isn't working.. any advice on how to do that?
Open your project and then go Project > Build Options > Compiler Flags . You can tick boxes in the "Compiler Flags" tab, and you can write other options in the "Other Options" tab. Do one or the other, e.g. don't tick the "-std=c++98" box and also put "-std=c++11" in the Other Options.
CMake does check for the compiler ids by compiling special C/C++ files. So no need to manually include from Module/Compiler or Module/Platform . This will be automatically done by CMake based on its compiler and platform checks. CMake: In which Order are Files parsed (Cache, Toolchain, …)?
Usually under Linux, one uses CMake to generate a GNU make file which then uses gcc or g++ to compile the source file and to create the executable. A CMake project is composed of source files and of one or several CMakeLists.
For CMake 3.0 or later, use the COMPILE_OPTIONS property to add a flag to a single translation unit, i.e.:
set_property(SOURCE MyFile.cpp APPEND PROPERTY COMPILE_OPTIONS "-msse4.1")
For earlier versions of CMake, use the COMPILE_FLAGS property. COMPILE_FLAGS
is a string property. Therefore the correct way to append additional options to it is to use the APPEND_STRING
variant of the set_property command:
set_property(SOURCE MyFile.cpp APPEND_STRING PROPERTY COMPILE_FLAGS " -msse4.1 ")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With