I'm writing a c++ program using CLion and I need to specify -O3 flag on the compiler, using set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" -O3)
on the CMakeList file does not work. Is there a way to do it?
Use either add_compile_options(-O3)
to add it globally or target_compile_options(YourTarget -O3)
to add it locally to a specific target.
You could also do it by using CMAKE_CXX_FLAGS
but that is a pretty old way of doing things in CMakeLists files, that's how it would look like: set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
or set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -O3)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.