Skip to content

Commit e4e889b

Browse files
committed
Fix more bugs
1 parent c766e02 commit e4e889b

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

CMakeLists.txt

+14-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ if (CMAKE_CROSSCOMPILING)
1313
endif()
1414

1515
if (APPLE AND NOT BIGNUM_NO)
16-
find_program("brew" brew)
16+
find_program(brew "brew")
1717
if (NOT brew STREQUAL "")
1818
# These Homebrew packages may be keg-only, meaning that they won't be found
1919
# in expected paths because they may conflict with system files. Ask
@@ -29,7 +29,7 @@ if (APPLE AND NOT BIGNUM_NO)
2929
set(GMP_LIBS "-L${gmp_prefix}/lib -lgmp")
3030
endif()
3131
else()
32-
find_program("port" port)
32+
find_program(port "port")
3333
# if homebrew isn't installed and macports is, add the macports default paths
3434
# as a last resort.
3535
if (NOT port STREQUAL "")
@@ -101,7 +101,16 @@ if (COVERAGE)
101101
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} --coverage")
102102
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --coverage")
103103
else()
104-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
104+
check_c_compiler_flag("-O3" OPTIMIZE_O3)
105+
if (OPTIMIZE_O3)
106+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
107+
else()
108+
# MSVC
109+
check_c_compiler_flag("/Ox" OPTIMIZE_OX)
110+
if (OPTIMIZE_OX)
111+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Ox")
112+
endif()
113+
endif()
105114
endif()
106115

107116
set(PRECOMP ${ECMULT_STATIC_PRECOMPUTATION})
@@ -110,7 +119,7 @@ if (NOT ASM_ARM)
110119
check_c_source_compiles("\
111120
#include <stdint.h> \n\
112121
uint64_t a = 11, tmp; \n\
113-
int main(void) {__asm__ __volatile__(\"movq 0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\");return 0;}" ASM_64BIT)
122+
int main(void) {__asm__ __volatile__(\"movq $0x100000000,%1; mulq %%rsi\" : \"+a\"(a) : \"S\"(tmp) : \"cc\", \"%rdx\");return 0;}" ASM_64BIT)
114123
if (ASM_64BIT)
115124
set(ASM_x86_64 ON)
116125
elseif(ASM_x86_64)
@@ -163,9 +172,7 @@ if (ASM_x86_64)
163172
# Define this symbol to enable x86_64 assembly optimizations
164173
add_compile_definitions(USE_ASM_X86_64=1)
165174
else()
166-
if(ASM_ARM)
167-
set(USE_EXTERNAL_ASM ON)
168-
endif()
175+
set(USE_EXTERNAL_ASM ${ASM_ARM})
169176
# no asm
170177
endif()
171178

src/CMakeLists.txt

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include_directories(${PROJECT_SOURCE_DIR})
2+
include_directories("${PROJECT_SOURCE_DIR}/include")
23

34
add_library(secp256k1 secp256k1.c)
45
if (TESTS)
@@ -10,15 +11,19 @@ endif()
1011

1112
if (PRECOMP)
1213
add_executable(precomputation gen_context.c)
13-
set_target_properties(precomputation PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_SOURCE_DIR}/src/")
1414
# alternatives considered:
15-
# add_file_dependencies, add_custom_target, add_custom_command
16-
add_dependencies(secp256k1 precomputation)
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)
1723
if (TESTS)
18-
add_dependencies(test precomputation)
24+
add_dependencies(test precomputed_table)
1925
endif()
2026
if (EXHAUSTIVE_TESTS)
21-
add_dependencies(exhaustive_test precomputation)
27+
add_dependencies(exhaustive_test precomputed_table)
2228
endif()
23-
execute_process(COMMAND "${PROJECT_SOURCE_DIR}/src/precomputation" WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
2429
endif()

0 commit comments

Comments
 (0)