From 718c7fbef6f20e933990ccb39aef9f0808118a97 Mon Sep 17 00:00:00 2001 From: DesWurstes Date: Wed, 19 Sep 2018 18:22:45 +0300 Subject: [PATCH] More improvements --- CMakeLists.txt | 74 ++++++++++++++++++++++++---------------------- src/CMakeLists.txt | 36 +++++++++++----------- 2 files changed, 57 insertions(+), 53 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e89b5854ba..4012af5e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,57 +4,55 @@ project(libsecp256k1 VERSION 0.1 LANGUAGES C) set(CMAKE_C_STANDARD 90) set(CMAKE_C_STANDARD_REQUIRED ON) -if (CMAKE_C_FLAGS STREQUAL "") - set(CMAKE_C_FLAGS "-g") -endif() +include(CheckCCompilerFlag) -if (CMAKE_CROSSCOMPILING) - message(FATAL_ERROR "Currently Cmake makefile doesn't support cross compiling.") +if (CMAKE_C_FLAGS STREQUAL "") + check_c_compiler_flag("-g" DEBUG_OPTION) + if (DEBUG_OPTION) + set(CMAKE_C_FLAGS "-g") + endif() endif() if (APPLE AND NOT BIGNUM_NO) find_program(brew "brew") - if (NOT brew STREQUAL "") + if (brew STREQUAL "") + find_program(port "port") + # if homebrew isn't installed and macports is, add the macports default paths + # as a last resort. + if (NOT port STREQUAL "") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem /opt/local/include") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L/opt/local/lib") + endif() + else() # These Homebrew packages may be keg-only, meaning that they won't be found # in expected paths because they may conflict with system files. Ask # Homebrew where each one is located, then adjust paths accordingly. execute_process(COMMAND ${brew} --prefix openssl OUTPUT_VARIABLE openssl_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process(COMMAND ${brew} --prefix gmp OUTPUT_VARIABLE gmp_prefix OUTPUT_STRIP_TRAILING_WHITESPACE) - if (NOT openssl_prefix STREQUAL "") - set(ENV{PKG_CONFIG_PATH} "${openssl_prefix}/lib/pkgconfig:$PKG_CONFIG_PATH") - endif() if (NOT gmp_prefix STREQUAL "") - set(ENV{PKG_CONFIG_PATH} "${gmp_prefix}/lib/pkgconfig:$PKG_CONFIG_PATH") set(GMP_C_FLAGS "-I${gmp_prefix}/include") set(GMP_LIBS "-L${gmp_prefix}/lib -lgmp") endif() - else() - find_program(port "port") - # if homebrew isn't installed and macports is, add the macports default paths - # as a last resort. - if (NOT port STREQUAL "") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem /opt/local/include") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L/opt/local/lib") - endif() endif() endif() -include(CheckCCompilerFlag) +check_c_compiler_flag("-W" WARN_ALL) +if (WARN_ALL) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W") +endif() + +set(WARN_FLAGS + "-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings" +) -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W") -set(WARN_C_FLAGS "-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings") -set(SAVED_C_FLAGS "${CMAKE_C_FLAGS}") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_C_FLAGS}") -check_c_compiler_flag(${CMAKE_C_FLAGS} USE_WARN_CFLAGS) -if (NOT USE_WARN_CFLAGS) - set(CMAKE_C_FLAGS "${SAVED_C_FLAGS}") +check_c_compiler_flag(${WARN_FLAGS} USE_WARN_CFLAGS) +if (USE_WARN_CFLAGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS}") endif() -set(SAVED_C_FLAGS "${CMAKE_C_FLAGS}") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") -check_c_compiler_flag(${CMAKE_C_FLAGS} USE_OPAQUE_CFLAGS) -if (NOT USE_OPAQUE_CFLAGS) - set(CMAKE_C_FLAGS "${SAVED_C_FLAGS}") +check_c_compiler_flag("-fvisibility=hidden" USE_OPAQUE_CFLAGS) +if (USE_OPAQUE_CFLAGS) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") endif() option(BENCHMARK "compile benchmark (default is on)" ON) @@ -84,10 +82,10 @@ option(ASM_NO "don't use any assembly optimization (default is auto)" OFF) include(CheckTypeSize) check_type_size("__int128" INT128) -if (NOT INT128 STREQUAL "") - set(INT128 ON) -else() +if (INT128 STREQUAL "") set(INT128 OFF) +else() + set(INT128 ON) endif() include(CheckCSourceCompiles) @@ -261,6 +259,12 @@ if (INT128) add_compile_definitions(HAVE___INT128=1) endif() +include(TestBigEndian) +test_big_endian(BIG_ENDIAN) +if (BIG_ENDIAN) + add_compile_definitions(WORDS_BIGENDIAN=1) +endif() + add_compile_definitions(SECP256K1_BUILD) message("Using static precomputation: ${PRECOMP}") @@ -268,8 +272,8 @@ message("Using x86_64 ASM: ${ASM_x86_64}") message("Using ARM ASM: ${ASM_ARM}") message("Using external ASM: ${USE_EXTERNAL_ASM}") message("Using 64 bit field implementation: ${FIELD_64BIT}") -message("Using GMP bignum implementation: ${BIGNUM_GMP}") message("Using 64 bit scalar implementation: ${SCALAR_64BIT}") +message("Using GMP bignum implementation: ${BIGNUM_GMP}") message("Using endomorphism optimizations: ${ENDOMORPHISM}") message("Building benchmarks: ${BENCHMARK}") message("Building for coverage analysis: ${COVERAGE}") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1f500a09de..4c145ea24e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,27 +3,27 @@ include_directories("${PROJECT_SOURCE_DIR}/include") add_library(secp256k1 secp256k1.c) if (TESTS) - add_executable(test tests.c) + add_executable(test tests.c) endif() if (EXHAUSTIVE_TESTS) - add_executable(exhaustive_test tests_exhaustive.c) + add_executable(exhaustive_test tests_exhaustive.c) endif() if (PRECOMP) - add_executable(precomputation gen_context.c) - # alternatives considered: - # add_file_dependencies, add_dependencies, add_custom_command - add_custom_target(precomputed_table - COMMAND "${PROJECT_SOURCE_DIR}/precomputation" - BYPRODUCTS "${PROJECT_SOURCE_DIR}/src/ecmult_static_context.h" - DEPENDS precomputation - WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} - ) - add_dependencies(secp256k1 precomputed_table) - if (TESTS) - add_dependencies(test precomputed_table) - endif() - if (EXHAUSTIVE_TESTS) - add_dependencies(exhaustive_test precomputed_table) - endif() + add_executable(precomputation gen_context.c) + # alternatives considered: + # add_file_dependencies, add_dependencies, add_custom_command + add_custom_target(precomputed_table + COMMAND "${PROJECT_SOURCE_DIR}/precomputation" + BYPRODUCTS "${PROJECT_SOURCE_DIR}/src/ecmult_static_context.h" + DEPENDS precomputation + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + add_dependencies(secp256k1 precomputed_table) + if (TESTS) + add_dependencies(test precomputed_table) + endif() + if (EXHAUSTIVE_TESTS) + add_dependencies(exhaustive_test precomputed_table) + endif() endif()