Optimize in CMake by default

后端 未结 3 1675
旧巷少年郎
旧巷少年郎 2020-12-13 00:39

I have a C++ project which uses CMake as its build system. I\'d like the following behavior:

If cmake is invoked as cmake .., then CMAKE_CXX_FLAGS

3条回答
  •  生来不讨喜
    2020-12-13 00:51

    For CXX flags specific for Release target, you should set
    CMAKE_CXX_FLAGS_RELEASE
    instead of
    CMAKE_CXX_FLAGS

    In your case you can use:

    set(CMAKE_CXX_FLAGS "-Wall -Wextra")
    set(CMAKE_CXX_FLAGS_DEBUG "-g")
    set(CMAKE_CXX_FLAGS_RELEASE "-O3")

    A more modern CMake approach (which I suggest, if you are using CMake version 2.8.12 or newer), is well described in this StackOverflow answer and involves the use of target_compile_options.

提交回复
热议问题