Skip to content

Commit

Permalink
Add basic support of build type (twitter#199)
Browse files Browse the repository at this point in the history
- debug build type to pass O0 flag, other to pass O2 flag
- remove unnecessary flags from COVERAGE -g -Wall -W
  • Loading branch information
michalbiesek authored and Yao Yue committed Jul 11, 2019
1 parent 7107988 commit 1c8df42
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
22 changes: 19 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,23 @@ configure_file(
# set compiler flags
# string concat is easier in 3.0, but older versions don't have the concat subcommand
# so we are using list as input until we move to new version
# TODO add build types
add_definitions(-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64)
# Set a default build type (Release) if none was specified

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()

if(CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
endif()

set(CMAKE_MACOSX_RPATH 1)
set(CFLAGS_LIST
"-std=c11 "
"-ggdb3 -O2 "
"-ggdb3 "
"-Wall "
"-Wmissing-prototypes -Wmissing-declarations -Wredundant-decls "
"-Wunused-function -Wunused-value -Wunused-variable "
Expand All @@ -133,7 +144,10 @@ if(CMAKE_COMPILER_IS_GNUCC)
endif()

if (COVERAGE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -O0 -Wall -W -fprofile-arcs -ftest-coverage")
if(NOT ${CMAKE_BUILD_TYPE} MATCHES Debug)
message(WARNING "Code coverage results with an optimised (non-Debug) build may be misleading" )
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage")
endif(COVERAGE)

# test dependencies
Expand Down Expand Up @@ -184,6 +198,8 @@ endif()
# print a summary #
###################

message(STATUS "CMAKE_BUILD_TYPE: " ${CMAKE_BUILD_TYPE})

message(STATUS "PLATFORM: " ${OS_PLATFORM})

message(STATUS "CPPFLAGS: " ${CMAKE_CPP_FLAGS})
Expand Down
2 changes: 1 addition & 1 deletion test-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash

set -e
rm -rf lcov _build _bin && mkdir _build && pushd _build && cmake -DCOVERAGE=on .. && make -j && make test && popd
rm -rf lcov _build _bin && mkdir _build && pushd _build && cmake -DCMAKE_BUILD_TYPE=Debug -DCOVERAGE=on .. && make -j && make test && popd
mkdir lcov
lcov --directory . --capture --output-file lcov/app.info
genhtml lcov/app.info -o lcov/html
Expand Down

0 comments on commit 1c8df42

Please sign in to comment.