@@ -4,57 +4,55 @@ project(libsecp256k1 VERSION 0.1 LANGUAGES C)
4
4
set (CMAKE_C_STANDARD 90)
5
5
set (CMAKE_C_STANDARD_REQUIRED ON )
6
6
7
- if (CMAKE_C_FLAGS STREQUAL "" )
8
- set (CMAKE_C_FLAGS "-g" )
9
- endif ()
7
+ include (CheckCCompilerFlag)
10
8
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 ()
13
14
endif ()
14
15
15
16
if (APPLE AND NOT BIGNUM_NO)
16
17
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 ()
18
27
# These Homebrew packages may be keg-only, meaning that they won't be found
19
28
# in expected paths because they may conflict with system files. Ask
20
29
# Homebrew where each one is located, then adjust paths accordingly.
21
30
execute_process (COMMAND ${brew} --prefix openssl OUTPUT_VARIABLE openssl_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
22
31
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 ()
26
32
if (NOT gmp_prefix STREQUAL "" )
27
- set (ENV{PKG_CONFIG_PATH} "${gmp_prefix} /lib/pkgconfig:$PKG_CONFIG_PATH" )
28
33
set (GMP_C_FLAGS "-I${gmp_prefix} /include" )
29
34
set (GMP_LIBS "-L${gmp_prefix} /lib -lgmp" )
30
35
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 ()
39
36
endif ()
40
37
endif ()
41
38
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
+ )
43
47
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} " )
51
51
endif ()
52
52
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" )
58
56
endif ()
59
57
60
58
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)
84
82
85
83
include (CheckTypeSize)
86
84
check_type_size("__int128" INT128)
87
- if (NOT INT128 STREQUAL "" )
88
- set (INT128 ON )
89
- else ()
85
+ if (INT128 STREQUAL "" )
90
86
set (INT128 OFF )
87
+ else ()
88
+ set (INT128 ON )
91
89
endif ()
92
90
93
91
include (CheckCSourceCompiles)
@@ -261,15 +259,21 @@ if (INT128)
261
259
add_compile_definitions (HAVE___INT128=1)
262
260
endif ()
263
261
262
+ include (TestBigEndian)
263
+ test_big_endian(BIG_ENDIAN)
264
+ if (BIG_ENDIAN)
265
+ add_compile_definitions (WORDS_BIGENDIAN=1)
266
+ endif ()
267
+
264
268
add_compile_definitions (SECP256K1_BUILD)
265
269
266
270
message ("Using static precomputation: ${PRECOMP} " )
267
271
message ("Using x86_64 ASM: ${ASM_x86_64} " )
268
272
message ("Using ARM ASM: ${ASM_ARM} " )
269
273
message ("Using external ASM: ${USE_EXTERNAL_ASM} " )
270
274
message ("Using 64 bit field implementation: ${FIELD_64BIT} " )
271
- message ("Using GMP bignum implementation: ${BIGNUM_GMP} " )
272
275
message ("Using 64 bit scalar implementation: ${SCALAR_64BIT} " )
276
+ message ("Using GMP bignum implementation: ${BIGNUM_GMP} " )
273
277
message ("Using endomorphism optimizations: ${ENDOMORPHISM} " )
274
278
message ("Building benchmarks: ${BENCHMARK} " )
275
279
message ("Building for coverage analysis: ${COVERAGE} " )
0 commit comments