Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/CMakeLists.txt
# Copyright (c) 2017 The Bitcoin developers | # Copyright (c) 2017 The Bitcoin developers | ||||
cmake_minimum_required(VERSION 3.13) | cmake_minimum_required(VERSION 3.13) | ||||
project(secp256k1 LANGUAGES C VERSION 0.1.0) | project(secp256k1 LANGUAGES C VERSION 0.1.0) | ||||
# Add path for custom modules when building as a standalone project | # Add path for custom modules when building as a standalone project | ||||
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) | list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/modules) | ||||
option(SECP256K1_ENABLE_COVERAGE "Enable coverage" OFF) | |||||
option(SECP256K1_ENABLE_BRANCH_COVERAGE "Enable branch coverage" OFF) | |||||
if(SECP256K1_ENABLE_COVERAGE) | |||||
include(Coverage) | |||||
enable_coverage(${SECP256K1_ENABLE_BRANCH_COVERAGE}) | |||||
file(GLOB COVERAGE_EXCLUDED_FILES src/bench*) | |||||
exclude_from_coverage(${COVERAGE_EXCLUDED_FILES}) | |||||
set(CMAKE_BUILD_TYPE Coverage CACHE STRING | |||||
"Select the configuration for the build" FORCE) | |||||
set(CMAKE_C_FLAGS_COVERAGE "-g -O0") | |||||
endif() | |||||
# Default to RelWithDebInfo configuration | # Default to RelWithDebInfo configuration | ||||
if(NOT CMAKE_BUILD_TYPE) | if(NOT CMAKE_BUILD_TYPE) | ||||
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING | ||||
"Select the configuration for the build" FORCE) | "Select the configuration for the build" FORCE) | ||||
endif() | endif() | ||||
# TODO: use -O0 instead of -O3 when coverage is enabled | |||||
set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3") | set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O3") | ||||
include(AddCompilerFlags) | include(AddCompilerFlags) | ||||
# libsecp256k1 use a different set of flags. | # libsecp256k1 use a different set of flags. | ||||
add_c_compiler_flags( | add_c_compiler_flags( | ||||
-pedantic | -pedantic | ||||
-Wall | -Wall | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | if(SECP256K1_BUILD_TEST) | ||||
create_test_suite(secp256k1) | create_test_suite(secp256k1) | ||||
function(create_secp256k1_test NAME FILES) | function(create_secp256k1_test NAME FILES) | ||||
add_test_to_suite(secp256k1 ${NAME} EXCLUDE_FROM_ALL ${FILES}) | add_test_to_suite(secp256k1 ${NAME} EXCLUDE_FROM_ALL ${FILES}) | ||||
link_secp256k1_internal(${NAME}) | link_secp256k1_internal(${NAME}) | ||||
endfunction() | endfunction() | ||||
create_secp256k1_test(tests src/tests.c) | create_secp256k1_test(tests src/tests.c) | ||||
target_compile_definitions(tests PRIVATE VERIFY) | |||||
create_secp256k1_test(exhaustive_tests src/tests_exhaustive.c) | create_secp256k1_test(exhaustive_tests src/tests_exhaustive.c) | ||||
# This should not be enabled at the same time as coverage is. | # This should not be enabled at the same time as coverage is. | ||||
# TODO: support coverage. | target_compile_definitions(tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>) | ||||
target_compile_definitions(exhaustive_tests PRIVATE VERIFY) | target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>) | ||||
deadalnix: I don't think that this is correct. You want VERIFY enabled for tests no matter if there is… | |||||
FabienAuthorUnsubmitted Done Inline ActionsHonestly I don't know. This has been added in https://github.com/bitcoin-core/secp256k1/pull/428 but there is no comment on why this is required. My bet is that it will decrease coverage statistics when there is no failure, because the check failed branch is never covered. Note that I am missing the COVERAGE definition (will update), that undefines VERIFY_CHECK as well: /* Like assert(), but when VERIFY is defined, and side-effect safe. */ #if defined(COVERAGE) #define VERIFY_CHECK(check) #define VERIFY_SETUP(stmt) #elif defined(VERIFY) #define VERIFY_CHECK CHECK #define VERIFY_SETUP(stmt) do { stmt; } while(0) #else #define VERIFY_CHECK(cond) do { (void)(cond); } while(0) #define VERIFY_SETUP(stmt) #endif Not sure what to do here, should I let VERIFY as standard and have different result than autotools ? Fabien: Honestly I don't know. This has been added in https://github.com/bitcoin… | |||||
if(SECP256K1_ENABLE_JNI) | if(SECP256K1_ENABLE_JNI) | ||||
set(SECP256k1_JNI_TEST_JAR "secp256k1-jni-test") | set(SECP256k1_JNI_TEST_JAR "secp256k1-jni-test") | ||||
set(CMAKE_JNI_TARGET TRUE) | set(CMAKE_JNI_TARGET TRUE) | ||||
add_jar(secp256k1-jni-test-jar | add_jar(secp256k1-jni-test-jar | ||||
SOURCES | SOURCES | ||||
src/java/org/bitcoin/NativeSecp256k1.java | src/java/org/bitcoin/NativeSecp256k1.java | ||||
Show All 27 Lines |
I don't think that this is correct. You want VERIFY enabled for tests no matter if there is coverage or not. Is there something I'm missing?