Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/CMakeLists.txt
Show All 34 Lines | |||||
include_directories( | include_directories( | ||||
. | . | ||||
src | src | ||||
# For the config | # For the config | ||||
${CMAKE_CURRENT_BINARY_DIR}/src | ${CMAKE_CURRENT_BINARY_DIR}/src | ||||
) | ) | ||||
# The library | # The library | ||||
add_library(secp256k1 src/secp256k1.c) | add_library(secp256k1-object OBJECT src/secp256k1.c) | ||||
target_include_directories(secp256k1 PUBLIC include) | target_include_directories(secp256k1-object PUBLIC include) | ||||
set(SECP256k1_LIBS "") | |||||
# We need to link in GMP | # We need to link in GMP | ||||
find_package(GMP) | find_package(GMP) | ||||
if(GMP_FOUND) | if(GMP_FOUND) | ||||
target_include_directories(secp256k1 PUBLIC ${GMP_INCLUDE_DIR}) | target_include_directories(secp256k1-object PUBLIC ${GMP_INCLUDE_DIR}) | ||||
target_link_libraries(secp256k1 ${GMP_LIBRARY}) | list(APPEND SECP256k1_LIBS ${GMP_LIBRARY}) | ||||
set(USE_NUM_GMP 1) | set(USE_NUM_GMP 1) | ||||
set(USE_FIELD_INV_NUM 1) | set(USE_FIELD_INV_NUM 1) | ||||
set(USE_SCALAR_INV_NUM 1) | set(USE_SCALAR_INV_NUM 1) | ||||
else() | else() | ||||
set(USE_NUM_NONE 1) | set(USE_NUM_NONE 1) | ||||
set(USE_FIELD_INV_BUILTIN 1) | set(USE_FIELD_INV_BUILTIN 1) | ||||
set(USE_SCALAR_INV_BUILTIN 1) | set(USE_SCALAR_INV_BUILTIN 1) | ||||
endif() | endif() | ||||
▲ Show 20 Lines • Show All 84 Lines • ▼ Show 20 Lines | if(SECP256K1_ECMULT_STATIC_PRECOMPUTATION) | ||||
include(NativeExecutable) | include(NativeExecutable) | ||||
add_native_executable(gen_context src/gen_context.c) | add_native_executable(gen_context src/gen_context.c) | ||||
add_custom_command( | add_custom_command( | ||||
OUTPUT ecmult_static_context.h | OUTPUT ecmult_static_context.h | ||||
COMMAND gen_context | COMMAND gen_context | ||||
) | ) | ||||
target_sources(secp256k1 PRIVATE ecmult_static_context.h) | target_sources(secp256k1-object PRIVATE ecmult_static_context.h) | ||||
endif() | endif() | ||||
# Generate the config | # Generate the config | ||||
configure_file(src/libsecp256k1-config.h.cmake.in src/libsecp256k1-config.h ESCAPE_QUOTES) | configure_file(src/libsecp256k1-config.h.cmake.in src/libsecp256k1-config.h ESCAPE_QUOTES) | ||||
target_compile_definitions(secp256k1 PRIVATE HAVE_CONFIG_H SECP256K1_BUILD) | target_compile_definitions(secp256k1-object PRIVATE HAVE_CONFIG_H SECP256K1_BUILD) | ||||
macro(build_secp256k1_library NAME TYPE) | |||||
add_library(${NAME} ${TYPE} $<TARGET_OBJECTS:secp256k1-object>) | |||||
# The following lines can be simplified with cmake >= 3.12: | |||||
# target_link_libraries(${NAME} secp256k1-object) | |||||
target_compile_definitions(${NAME} PRIVATE $<TARGET_PROPERTY:secp256k1-object,COMPILE_DEFINITIONS>) | |||||
target_include_directories(${NAME} PUBLIC $<TARGET_PROPERTY:secp256k1-object,INCLUDE_DIRECTORIES>) | |||||
target_link_libraries(${NAME} ${SECP256k1_LIBS}) | |||||
set_target_properties(${NAME} PROPERTIES OUTPUT_NAME "secp256k1") | |||||
endmacro() | |||||
# Build the static secp256k1 library | |||||
build_secp256k1_library(secp256k1 STATIC) | |||||
option(SECP256K1_BUILD_SHARED "Build secp256k1 as a shared library" OFF) | |||||
if(SECP256K1_BUILD_SHARED) | |||||
# CMake will automatically set the PIC option to the shared library, but not | |||||
# when building the object library files, causing a linker failure. | |||||
set_target_properties(secp256k1-object PROPERTIES POSITION_INDEPENDENT_CODE ON) | |||||
build_secp256k1_library(secp256k1-shared SHARED) | |||||
endif() | |||||
deadalnix: You shouldn't hide the definition behind a option. If JNI test require it, they should find the… | |||||
# Tests | # Tests | ||||
option(SECP256K1_BUILD_TEST "Build secp256k1's unit tests" ON) | option(SECP256K1_BUILD_TEST "Build secp256k1's unit tests" ON) | ||||
if(SECP256K1_BUILD_TEST) | if(SECP256K1_BUILD_TEST) | ||||
include(TestSuite) | include(TestSuite) | ||||
create_test_suite(secp256k1) | create_test_suite(secp256k1) | ||||
function(create_secp256k1_test NAME FILES) | function(create_secp256k1_test NAME FILES) | ||||
Show All 17 Lines |
You shouldn't hide the definition behind a option. If JNI test require it, they should find the definition.
It is however possible to exclude the library from the all target or not, based on the option.