Minh Nghĩa
Minh Nghĩa

Reputation: 1059

How to make CLion use different CMake config for debug and release?

I built 2 separate debug and release versions of OpenCV. How can I switch between 2 builds when I debug my project? I tried this:

IF(CMAKE_BUILD_TYPE MATCHES DEBUG)
    message(WARNING "debug mode")
    find_package(OpenCV REQUIRED
            PATHS /path/to/debug/build NO_DEFAULT_PATH)
ELSE()
    message(WARNING "release mode")
    find_package(OpenCV REQUIRED)
ENDIF()

but it doesn't work. It does show release mode when I build normally, but doesn't show debug mode or release mode when the debugger kicks in. My thought is that CMAKE_BUILD_TYPE will be set to Debug when I debug. Is that true?

Thanks for your help.

Upvotes: 0

Views: 637

Answers (1)

KamilCuk
KamilCuk

Reputation: 141920

MATCHES in cmake if is case sensitive. So when comparing CMAKE_BUILD_TYPE you have to decide on case. It's popular to convert to string into upper case and do comparisons then:

string(TOUPPER ${CMAKE_BUILD_TYPE} CMAKE_BUILD_TYPE_UP)
if (${CMAKE_BUILD_TYPE_UP} STREQUAL "DEBUG")
   ...

Or the best is to compare against the standard values defiuned in cmake docs: Possible values are empty, Debug, Release, RelWithDebInfo and MinSizeRel. Note that both cmake -DCMAKE_BUILD_TYPE=dEbUg and cmake -DCMAKE_BUILD_TYPE=DeBuG both will configure for Debug build, but the CMAKE_BUILD_TYPE variable will differ. So the safest way is to convert it to upper case.

Upvotes: 1

Related Questions