Skip to content

Commit

Permalink
Explicitly set CMAKE_XXX_FLAGS_DEBUG
Browse files Browse the repository at this point in the history
Explicitly set the C/C++ CMake Debug flags (CMAKE_C_FLAGS_DEBUG /
CMAKE_CXX_FLAGS_DEBUG) for all supported compilers, with optimization
disabled. This allows us to use this variable to selectively force
Debug flags (i.e. optimization off) for selected targets, such as unit
tests.

Change-Id: Iaafc3d8c8b289fa49105780944f71a890ce95edc
Reviewed-on: http://review.couchbase.org/55457
Reviewed-by: Trond Norbye <trond.norbye@gmail.com>
Tested-by: Trond Norbye <trond.norbye@gmail.com>
  • Loading branch information
daverigby authored and trondn committed Sep 23, 2015
1 parent f747c82 commit dfc6abe
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseClangOptions.cmake
Expand Up @@ -8,6 +8,7 @@ SET(CB_CLANG_LANG_VER "-std=gnu99")
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -g")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")

IF ("${ENABLE_WERROR}" STREQUAL "YES")
SET(CB_CLANG_WERROR "-Werror")
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseClangxxOptions.cmake
Expand Up @@ -7,6 +7,7 @@ SET(CB_CLANGXX_THREAD "-pthread")
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -g")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

IF ("${ENABLE_WERROR}" STREQUAL "YES")
SET(CB_CLANGXX_WERROR "-Werror")
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseGccOptions.cmake
Expand Up @@ -8,6 +8,7 @@ SET(CB_GNU_LANG_VER "-std=gnu99")
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -g")
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")

IF ("${ENABLE_WERROR}" STREQUAL "YES")
SET(CB_GNU_WERROR "-Werror")
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseGxxOptions.cmake
Expand Up @@ -7,6 +7,7 @@ SET(CB_GXX_THREAD "-pthread")
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -DNDEBUG -g")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")

IF ("${ENABLE_WERROR}" STREQUAL "YES")
SET(CB_GXX_WERROR "-Werror")
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseMsvcOptions.cmake
Expand Up @@ -11,6 +11,7 @@ ENDIF()
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_C_FLAGS_RELEASE "/MD /O2 /Ob2 /D NDEBUG")
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "/MD /O2 /Ob2 /D NDEBUG /Zi")
SET(CMAKE_C_FLAGS_DEBUG "/MD /Od /Ob0 /Zi")

SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CB_MSVC_DEBUG} ${CB_MSVC_WARNINGS} ${CB_MSVC_VISIBILITY} ${CB_MSVC_THREAD} ${CB_MSVC_WERROR}")
SET(CMAKE_LINK_FLAGS "${CMAKE_LINK_FLAGS} ${CB_MSVC_LDFLAGS}")
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/CouchbaseMsvcxxOptions.cmake
Expand Up @@ -11,6 +11,7 @@ ENDIF()
# Release, only differing in whether debugging information is enabled.
SET(CMAKE_CXX_FLAGS_RELEASE "/MD /O2 /Ob2 /D NDEBUG")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /O2 /Ob2 /D NDEBUG /Zi")
SET(CMAKE_CXX_FLAGS_DEBUG "/MD /Od /Ob0 /Zi")

# C++11 support has gradually increased in MSVC starting with 2010 (v16), but
# we declare that at least VS 2013 (v18) is needed for std::atomic / C99.
Expand Down
39 changes: 39 additions & 0 deletions cmake/Modules/README.md
@@ -0,0 +1,39 @@
# CMake modules

Some brief description / explanation of the use of certain files and
variables.


## CouchbaseXXX.cmake files

These files are used to define Couchbase-specific macros and
variables. For example, they define the the various compiler flags for
each supported compiler, supported memory allocator options, etc.

### Couchbase<Compiler>Options.cmake

These files define the default compilation flags for each of the
various supported compilers.

Descriptions of specific variables of interest:

* CMAKE_CXX_FLAGS_RELEASE / CMAKE_CXX_FLAGS_RELWITH_DEBINFO: Compiler
flags for Release and RelWIthDebInfo builds. Note that as of 4.0 we
actually ship a RelWithDebInfo build (to maximise our ability to
debug issues from the field) and hence
CMAKE_CXX_FLAGS_RELWITH_DEBINFO are overridden to be as optimized
as the normal Release flags, but keeping debug enabled.

* CMAKE_CXX_FLAGS_DEBUG: Compiler flags for Debug builds. We override
this to explicitly set Debug to have Optimization disabled (by
default it just uses the implicit default). This allows us to use
this variable to selectively force Debug flags (i.e. optimization
off) for selected targets, such as unit tests.


## FindCouchbaseXXX.cmake files

These files are similar to the standard CMake FindXXX.cmake files,
except Couchbase-specific files. The main purpose of the 'Couchbase'
prefix is just to make it obvious which are ours and which are
standard when used.

0 comments on commit dfc6abe

Please sign in to comment.