Skip to content

Commit

Permalink
More improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
DesWurstes committed Sep 19, 2018
1 parent e4e889b commit 718c7fb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 53 deletions.
74 changes: 39 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -261,15 +259,21 @@ 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}")
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}")
Expand Down
36 changes: 18 additions & 18 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 718c7fb

Please sign in to comment.