JayJona
JayJona

Reputation: 502

Clion compile with -O3

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?

Upvotes: 1

Views: 873

Answers (1)

ixSci
ixSci

Reputation: 13698

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

Upvotes: 2

Related Questions