Skip to content

Commit 6940f54

Browse files
committed
Completed cmake_ndebug_test
Tested with Visual Studio, NDEBUG=1 for all but Debug builds.
1 parent 0c611d5 commit 6940f54

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

cmake/CMakeLists.txt

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
cmake_minimum_required(VERSION 2.8)
22
project(workshop-cmake)
33

4-
add_executable(cmake_ndebug_test)
4+
configure_file(
5+
${CMAKE_SOURCE_DIR}/cmake_build_type.h.in
6+
${CMAKE_BINARY_DIR}/cmake_build_type.h
7+
@ONLY)
8+
9+
include_directories(${CMAKE_BINARY_DIR})
10+
11+
add_executable(cmake_ndebug_test cmake_ndebug_test.cpp)

cmake/cmake_build_type.h.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#define CMAKE_BUILD_TYPE "@CMAKE_BUILD_TYPE@"

cmake/cmake_ndebug_test.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1-
//
21
// Does CMake define NDEBUG in non-Debug builds?
3-
//
2+
#include "cmake_build_type.h"
43
#include <cstdio>
4+
55
int main()
66
{
7+
// Possible values are empty, Debug, Release, RelWithDebInfo and MinSizeRel.
8+
// This variable is only supported for make based generators.
9+
std::printf("CMAKE_BUILD_TYPE=%s\n", CMAKE_BUILD_TYPE);
710
#ifdef NDEBUG
11+
std::printf("NDEBUG=%d\n", NDEBUG);
812
#else
13+
std::puts("NDEBUG not defined");
914
#endif
10-
1115
}

0 commit comments

Comments
 (0)