Skip to content

Commit 718c7fb

Browse files
committed
More improvements
1 parent e4e889b commit 718c7fb

File tree

2 files changed

+57
-53
lines changed

2 files changed

+57
-53
lines changed

CMakeLists.txt

+39-35
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,55 @@ project(libsecp256k1 VERSION 0.1 LANGUAGES C)
44
set(CMAKE_C_STANDARD 90)
55
set(CMAKE_C_STANDARD_REQUIRED ON)
66

7-
if (CMAKE_C_FLAGS STREQUAL "")
8-
set(CMAKE_C_FLAGS "-g")
9-
endif()
7+
include(CheckCCompilerFlag)
108

11-
if (CMAKE_CROSSCOMPILING)
12-
message(FATAL_ERROR "Currently Cmake makefile doesn't support cross compiling.")
9+
if (CMAKE_C_FLAGS STREQUAL "")
10+
check_c_compiler_flag("-g" DEBUG_OPTION)
11+
if (DEBUG_OPTION)
12+
set(CMAKE_C_FLAGS "-g")
13+
endif()
1314
endif()
1415

1516
if (APPLE AND NOT BIGNUM_NO)
1617
find_program(brew "brew")
17-
if (NOT brew STREQUAL "")
18+
if (brew STREQUAL "")
19+
find_program(port "port")
20+
# if homebrew isn't installed and macports is, add the macports default paths
21+
# as a last resort.
22+
if (NOT port STREQUAL "")
23+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem /opt/local/include")
24+
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L/opt/local/lib")
25+
endif()
26+
else()
1827
# These Homebrew packages may be keg-only, meaning that they won't be found
1928
# in expected paths because they may conflict with system files. Ask
2029
# Homebrew where each one is located, then adjust paths accordingly.
2130
execute_process(COMMAND ${brew} --prefix openssl OUTPUT_VARIABLE openssl_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
2231
execute_process(COMMAND ${brew} --prefix gmp OUTPUT_VARIABLE gmp_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
23-
if (NOT openssl_prefix STREQUAL "")
24-
set(ENV{PKG_CONFIG_PATH} "${openssl_prefix}/lib/pkgconfig:$PKG_CONFIG_PATH")
25-
endif()
2632
if (NOT gmp_prefix STREQUAL "")
27-
set(ENV{PKG_CONFIG_PATH} "${gmp_prefix}/lib/pkgconfig:$PKG_CONFIG_PATH")
2833
set(GMP_C_FLAGS "-I${gmp_prefix}/include")
2934
set(GMP_LIBS "-L${gmp_prefix}/lib -lgmp")
3035
endif()
31-
else()
32-
find_program(port "port")
33-
# if homebrew isn't installed and macports is, add the macports default paths
34-
# as a last resort.
35-
if (NOT port STREQUAL "")
36-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -isystem /opt/local/include")
37-
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -L/opt/local/lib")
38-
endif()
3936
endif()
4037
endif()
4138

42-
include(CheckCCompilerFlag)
39+
check_c_compiler_flag("-W" WARN_ALL)
40+
if (WARN_ALL)
41+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W")
42+
endif()
43+
44+
set(WARN_FLAGS
45+
"-std=c89 -pedantic -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes -Wno-unused-function -Wno-long-long -Wno-overlength-strings"
46+
)
4347

44-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W")
45-
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")
46-
set(SAVED_C_FLAGS "${CMAKE_C_FLAGS}")
47-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_C_FLAGS}")
48-
check_c_compiler_flag(${CMAKE_C_FLAGS} USE_WARN_CFLAGS)
49-
if (NOT USE_WARN_CFLAGS)
50-
set(CMAKE_C_FLAGS "${SAVED_C_FLAGS}")
48+
check_c_compiler_flag(${WARN_FLAGS} USE_WARN_CFLAGS)
49+
if (USE_WARN_CFLAGS)
50+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARN_FLAGS}")
5151
endif()
5252

53-
set(SAVED_C_FLAGS "${CMAKE_C_FLAGS}")
54-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
55-
check_c_compiler_flag(${CMAKE_C_FLAGS} USE_OPAQUE_CFLAGS)
56-
if (NOT USE_OPAQUE_CFLAGS)
57-
set(CMAKE_C_FLAGS "${SAVED_C_FLAGS}")
53+
check_c_compiler_flag("-fvisibility=hidden" USE_OPAQUE_CFLAGS)
54+
if (USE_OPAQUE_CFLAGS)
55+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden")
5856
endif()
5957

6058
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)
8482

8583
include(CheckTypeSize)
8684
check_type_size("__int128" INT128)
87-
if (NOT INT128 STREQUAL "")
88-
set(INT128 ON)
89-
else()
85+
if (INT128 STREQUAL "")
9086
set(INT128 OFF)
87+
else()
88+
set(INT128 ON)
9189
endif()
9290

9391
include(CheckCSourceCompiles)
@@ -261,15 +259,21 @@ if (INT128)
261259
add_compile_definitions(HAVE___INT128=1)
262260
endif()
263261

262+
include(TestBigEndian)
263+
test_big_endian(BIG_ENDIAN)
264+
if (BIG_ENDIAN)
265+
add_compile_definitions(WORDS_BIGENDIAN=1)
266+
endif()
267+
264268
add_compile_definitions(SECP256K1_BUILD)
265269

266270
message("Using static precomputation: ${PRECOMP}")
267271
message("Using x86_64 ASM: ${ASM_x86_64}")
268272
message("Using ARM ASM: ${ASM_ARM}")
269273
message("Using external ASM: ${USE_EXTERNAL_ASM}")
270274
message("Using 64 bit field implementation: ${FIELD_64BIT}")
271-
message("Using GMP bignum implementation: ${BIGNUM_GMP}")
272275
message("Using 64 bit scalar implementation: ${SCALAR_64BIT}")
276+
message("Using GMP bignum implementation: ${BIGNUM_GMP}")
273277
message("Using endomorphism optimizations: ${ENDOMORPHISM}")
274278
message("Building benchmarks: ${BENCHMARK}")
275279
message("Building for coverage analysis: ${COVERAGE}")

src/CMakeLists.txt

+18-18
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ include_directories("${PROJECT_SOURCE_DIR}/include")
33

44
add_library(secp256k1 secp256k1.c)
55
if (TESTS)
6-
add_executable(test tests.c)
6+
add_executable(test tests.c)
77
endif()
88
if (EXHAUSTIVE_TESTS)
9-
add_executable(exhaustive_test tests_exhaustive.c)
9+
add_executable(exhaustive_test tests_exhaustive.c)
1010
endif()
1111

1212
if (PRECOMP)
13-
add_executable(precomputation gen_context.c)
14-
# alternatives considered:
15-
# add_file_dependencies, add_dependencies, add_custom_command
16-
add_custom_target(precomputed_table
17-
COMMAND "${PROJECT_SOURCE_DIR}/precomputation"
18-
BYPRODUCTS "${PROJECT_SOURCE_DIR}/src/ecmult_static_context.h"
19-
DEPENDS precomputation
20-
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
21-
)
22-
add_dependencies(secp256k1 precomputed_table)
23-
if (TESTS)
24-
add_dependencies(test precomputed_table)
25-
endif()
26-
if (EXHAUSTIVE_TESTS)
27-
add_dependencies(exhaustive_test precomputed_table)
28-
endif()
13+
add_executable(precomputation gen_context.c)
14+
# alternatives considered:
15+
# add_file_dependencies, add_dependencies, add_custom_command
16+
add_custom_target(precomputed_table
17+
COMMAND "${PROJECT_SOURCE_DIR}/precomputation"
18+
BYPRODUCTS "${PROJECT_SOURCE_DIR}/src/ecmult_static_context.h"
19+
DEPENDS precomputation
20+
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
21+
)
22+
add_dependencies(secp256k1 precomputed_table)
23+
if (TESTS)
24+
add_dependencies(test precomputed_table)
25+
endif()
26+
if (EXHAUSTIVE_TESTS)
27+
add_dependencies(exhaustive_test precomputed_table)
28+
endif()
2929
endif()

0 commit comments

Comments
 (0)