From 2d44f865c3bc49a3ae8552d9445e71ff5945371d Mon Sep 17 00:00:00 2001 From: dota17 Date: Sat, 29 Feb 2020 15:32:42 +0800 Subject: [PATCH 1/3] modify json-c default build type, and fix up the assert() errors in testcase --- CMakeLists.txt | 8 ++++++++ tests/CMakeLists.txt | 5 ----- tests/test_deep_copy.c | 5 +++++ tests/test_json_pointer.c | 5 +++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c7b5195..8e4fb2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,11 @@ if(POLICY CMP0054) cmake_policy(SET CMP0054 NEW) endif() +# set default build type if not specified by user +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE debug) +endif() + # Include file check macros honor CMAKE_REQUIRED_LIBRARIES # i.e. the check_include_file() calls will include -lm when checking. if(POLICY CMP0075) @@ -238,6 +243,9 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701") endif() +set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") +set(CMAKE_C_FLAGS_Release "${CMAKE_C_FLAGS_Release} -O2") + if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")) check_c_source_compiles( [=[ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 15e3258..d452017 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,8 +52,3 @@ target_link_libraries( endforeach(TESTNAME) -# Make sure NDEBUG is always undefined for tests -if (UNIX OR MINGW OR CYGWIN) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -UNDEBUG") -endif() - diff --git a/tests/test_deep_copy.c b/tests/test_deep_copy.c index baa4e09..645b0ce 100644 --- a/tests/test_deep_copy.c +++ b/tests/test_deep_copy.c @@ -2,7 +2,12 @@ #include #include #include +#ifdef NDEBUG +#undef NDEBUG #include +#else +#include +#endif #include #include diff --git a/tests/test_json_pointer.c b/tests/test_json_pointer.c index 7891e21..9d4a54a 100644 --- a/tests/test_json_pointer.c +++ b/tests/test_json_pointer.c @@ -1,6 +1,11 @@ #include "strerror_override.h" #include "strerror_override_private.h" +#ifdef NDEBUG +#undef NDEBUG #include +#else +#include +#endif #include #include From e56ab0146f9a30e2d5deec2cccf195ed13abc1c4 Mon Sep 17 00:00:00 2001 From: dota17 Date: Mon, 2 Mar 2020 20:19:35 +0800 Subject: [PATCH 2/3] update testcase and delete debug -O0 build --- CMakeLists.txt | 5 ++--- tests/test_deep_copy.c | 4 +--- tests/test_json_pointer.c | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8e4fb2a..0354553 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,8 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif() +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELAESE} -O2") + # Include file check macros honor CMAKE_REQUIRED_LIBRARIES # i.e. the check_include_file() calls will include -lm when checking. if(POLICY CMP0075) @@ -243,9 +245,6 @@ elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4701") endif() -set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0") -set(CMAKE_C_FLAGS_Release "${CMAKE_C_FLAGS_Release} -O2") - if (NOT ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")) check_c_source_compiles( [=[ diff --git a/tests/test_deep_copy.c b/tests/test_deep_copy.c index 645b0ce..a913015 100644 --- a/tests/test_deep_copy.c +++ b/tests/test_deep_copy.c @@ -4,10 +4,8 @@ #include #ifdef NDEBUG #undef NDEBUG -#include -#else -#include #endif +#include #include #include diff --git a/tests/test_json_pointer.c b/tests/test_json_pointer.c index 9d4a54a..f98a6a2 100644 --- a/tests/test_json_pointer.c +++ b/tests/test_json_pointer.c @@ -2,10 +2,8 @@ #include "strerror_override_private.h" #ifdef NDEBUG #undef NDEBUG -#include -#else -#include #endif +#include #include #include From 0030e905b4bf2250a9e2f5e18079f3b4fc49b22d Mon Sep 17 00:00:00 2001 From: dota17 Date: Tue, 3 Mar 2020 14:16:13 +0800 Subject: [PATCH 3/3] modify RELEASE --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0354553..95b8663 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ if(NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE debug) endif() -set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELAESE} -O2") +set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") # Include file check macros honor CMAKE_REQUIRED_LIBRARIES # i.e. the check_include_file() calls will include -lm when checking.