From e2ee3b8d85654a92c702f30f7bb4c594f6405ec4 Mon Sep 17 00:00:00 2001 From: Daniel Scharrer Date: Sun, 30 Jun 2013 13:42:35 +0200 Subject: [PATCH] Allow to enable debug output in release builds --- CMakeLists.txt | 9 +++++++++ README.md | 20 +++++++++++--------- cmake/BuildType.cmake | 4 ---- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f4482cf..edae314 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,15 @@ option(DEBUG_EXTRA "Expensive debug options" OFF) option(SET_WARNING_FLAGS "Adjust compiler warning flags" ON) option(SET_OPTIMIZATION_FLAGS "Adjust compiler optimization flags" ON) option(USE_CXX11 "Try to use C++11 if available" ON) +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(IS_DEBUG_BUILD ON) +else() + set(IS_DEBUG_BUILD OFF) +endif() +option(DEBUG "Enable debug output and runtime checks" ${IS_DEBUG_BUILD}) +if(DEBUG) + add_definitions(-DDEBUG=1) +endif() set(default_USE_STATIC_LIBS OFF) if(WIN32) diff --git a/README.md b/README.md index b6f89ee..457f6bf 100644 --- a/README.md +++ b/README.md @@ -44,18 +44,20 @@ Build options: |:------------------------ |:---------:|:----------- | | `USE_LZMA` | `ON` | Use `liblzma` if available. | `CMAKE_BUILD_TYPE` | `Release` | Set to `Debug` to enable debug output. +| `DEBUG` | `OFF`^1 | Enable debug output and runtime checks. +| `DEBUG_EXTRA` | `OFF` | Expensive debug options. | `SET_WARNING_FLAGS` | `ON` | Adjust compiler warning flags. This should not affect the produced binaries but is useful to catch potential problems. | `SET_OPTIMIZATION_FLAGS` | `ON` | Adjust compiler optimization flags. For non-debug builds the only thing this does is instruct the linker to only link against libraries that are actually needed. | `USE_CXX11` | `ON` | Try to compile in C++11 mode if available. -| `DEBUG_EXTRA` | `OFF` | Expensive debug options. -| `USE_STATIC_LIBS` | `OFF`^1 | Turns on static linking for all libraries, including `-static-libgcc` and `-static-libstdc++`. You can also use the individual options below: -| `LZMA_USE_STATIC_LIBS` | `OFF`^2 | Statically link `liblzma`. -| `Boost_USE_STATIC_LIBS` | `OFF`^2 | Statically link Boost. See also `FindBoost.cmake` -| `ZLIB_USE_STATIC_LIBS` | `OFF`^2 | Statically link `libz`. (used via Boost) -| `BZip2_USE_STATIC_LIBS` | `OFF`^2 | Statically link `libbz2`. (used via Boost) -| `iconv_USE_STATIC_LIBS` | `OFF`^2 | Statically link `libiconv`. -1. Under Windows, the default is `ON`. -2. Default is `ON` if `USE_STATIC_LIBS` is enabled. +| `USE_STATIC_LIBS` | `OFF`^2 | Turns on static linking for all libraries, including `-static-libgcc` and `-static-libstdc++`. You can also use the individual options below: +| `LZMA_USE_STATIC_LIBS` | `OFF`^3 | Statically link `liblzma`. +| `Boost_USE_STATIC_LIBS` | `OFF`^3 | Statically link Boost. See also `FindBoost.cmake` +| `ZLIB_USE_STATIC_LIBS` | `OFF`^3 | Statically link `libz`. (used via Boost) +| `BZip2_USE_STATIC_LIBS` | `OFF`^3 | Statically link `libbz2`. (used via Boost) +| `iconv_USE_STATIC_LIBS` | `OFF`^3 | Statically link `libiconv`. +1. Enabled automatically if `CMAKE_BUILD_TYPE` is set to `Debug`. +2. Under Windows, the default is `ON`. +3. Default is `ON` if `USE_STATIC_LIBS` is enabled. Install options: diff --git a/cmake/BuildType.cmake b/cmake/BuildType.cmake index c829e49..9214ba6 100644 --- a/cmake/BuildType.cmake +++ b/cmake/BuildType.cmake @@ -8,10 +8,6 @@ option(SET_OPTIMIZATION_FLAGS "Adjust compiler optimization flags" ON) if(CMAKE_BUILD_TYPE STREQUAL "") set(CMAKE_BUILD_TYPE "Release") endif() -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DDEBUG) - set(DEBUG 1) -endif() if(MSVC)