csecp256k1

Haskell FFI bindings to bitcoin-core/secp256k1 (docs.ppad.tech/csecp256k1).
git clone git://git.ppad.tech/csecp256k1.git
Log | Files | Refs | README | LICENSE

CMakeLists.txt (7159B)


      1 # Must be included before CMAKE_INSTALL_INCLUDEDIR is used.
      2 include(GNUInstallDirs)
      3 
      4 add_library(haskellsecp256k1_v0_1_0_precomputed OBJECT EXCLUDE_FROM_ALL
      5   precomputed_ecmult.c
      6   precomputed_ecmult_gen.c
      7 )
      8 
      9 # Add objects explicitly rather than linking to the object libs to keep them
     10 # from being exported.
     11 add_library(secp256k1 secp256k1.c $<TARGET_OBJECTS:haskellsecp256k1_v0_1_0_precomputed>)
     12 
     13 add_library(haskellsecp256k1_v0_1_0_asm INTERFACE)
     14 if(SECP256K1_ASM STREQUAL "arm32")
     15   add_library(haskellsecp256k1_v0_1_0_asm_arm OBJECT EXCLUDE_FROM_ALL)
     16   target_sources(haskellsecp256k1_v0_1_0_asm_arm PUBLIC
     17     asm/field_10x26_arm.s
     18   )
     19   target_sources(secp256k1 PRIVATE $<TARGET_OBJECTS:haskellsecp256k1_v0_1_0_asm_arm>)
     20   target_link_libraries(haskellsecp256k1_v0_1_0_asm INTERFACE haskellsecp256k1_v0_1_0_asm_arm)
     21 endif()
     22 
     23 if(WIN32)
     24   # Define our export symbol only for shared libs.
     25   set_target_properties(secp256k1 PROPERTIES DEFINE_SYMBOL SECP256K1_DLL_EXPORT)
     26   target_compile_definitions(secp256k1 INTERFACE $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SECP256K1_STATIC>)
     27 endif()
     28 
     29 # Object libs don't know if they're being built for a shared or static lib.
     30 # Grab the PIC property from secp256k1 which knows.
     31 get_target_property(use_pic secp256k1 POSITION_INDEPENDENT_CODE)
     32 set_target_properties(haskellsecp256k1_v0_1_0_precomputed PROPERTIES POSITION_INDEPENDENT_CODE ${use_pic})
     33 
     34 target_include_directories(secp256k1 INTERFACE
     35   # Add the include path for parent projects so that they don't have to manually add it.
     36   $<BUILD_INTERFACE:$<$<NOT:$<BOOL:${PROJECT_IS_TOP_LEVEL}>>:${PROJECT_SOURCE_DIR}/include>>
     37   $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
     38 )
     39 
     40 # This emulates Libtool to make sure Libtool and CMake agree on the ABI version,
     41 # see below "Calculate the version variables" in build-aux/ltmain.sh.
     42 math(EXPR ${PROJECT_NAME}_soversion "${${PROJECT_NAME}_LIB_VERSION_CURRENT} - ${${PROJECT_NAME}_LIB_VERSION_AGE}")
     43 set_target_properties(secp256k1 PROPERTIES
     44   SOVERSION ${${PROJECT_NAME}_soversion}
     45 )
     46 if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
     47   set_target_properties(secp256k1 PROPERTIES
     48     VERSION ${${PROJECT_NAME}_soversion}.${${PROJECT_NAME}_LIB_VERSION_AGE}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
     49   )
     50 elseif(APPLE)
     51   if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.17)
     52     math(EXPR ${PROJECT_NAME}_compatibility_version "${${PROJECT_NAME}_LIB_VERSION_CURRENT} + 1")
     53     set_target_properties(secp256k1 PROPERTIES
     54       MACHO_COMPATIBILITY_VERSION ${${PROJECT_NAME}_compatibility_version}
     55       MACHO_CURRENT_VERSION ${${PROJECT_NAME}_compatibility_version}.${${PROJECT_NAME}_LIB_VERSION_REVISION}
     56     )
     57     unset(${PROJECT_NAME}_compatibility_version)
     58   elseif(BUILD_SHARED_LIBS)
     59     message(WARNING
     60       "The 'compatibility version' and 'current version' values of the DYLIB "
     61       "will diverge from the values set by the GNU Libtool. To ensure "
     62       "compatibility, it is recommended to upgrade CMake to at least version 3.17."
     63     )
     64   endif()
     65 elseif(CMAKE_SYSTEM_NAME STREQUAL "Windows")
     66   set(${PROJECT_NAME}_windows "secp256k1")
     67   if(MSVC)
     68     set(${PROJECT_NAME}_windows "${PROJECT_NAME}")
     69   endif()
     70   set_target_properties(secp256k1 PROPERTIES
     71     ARCHIVE_OUTPUT_NAME "${${PROJECT_NAME}_windows}"
     72     RUNTIME_OUTPUT_NAME "${${PROJECT_NAME}_windows}-${${PROJECT_NAME}_soversion}"
     73   )
     74   unset(${PROJECT_NAME}_windows)
     75 endif()
     76 unset(${PROJECT_NAME}_soversion)
     77 
     78 if(SECP256K1_BUILD_BENCHMARK)
     79   add_executable(bench bench.c)
     80   target_link_libraries(bench secp256k1)
     81   add_executable(bench_internal bench_internal.c)
     82   target_link_libraries(bench_internal haskellsecp256k1_v0_1_0_precomputed haskellsecp256k1_v0_1_0_asm)
     83   add_executable(bench_ecmult bench_ecmult.c)
     84   target_link_libraries(bench_ecmult haskellsecp256k1_v0_1_0_precomputed haskellsecp256k1_v0_1_0_asm)
     85 endif()
     86 
     87 if(SECP256K1_BUILD_TESTS)
     88   add_executable(noverify_tests tests.c)
     89   target_link_libraries(noverify_tests haskellsecp256k1_v0_1_0_precomputed haskellsecp256k1_v0_1_0_asm)
     90   add_test(NAME noverify_tests COMMAND noverify_tests)
     91   if(NOT CMAKE_BUILD_TYPE STREQUAL "Coverage")
     92     add_executable(tests tests.c)
     93     target_compile_definitions(tests PRIVATE VERIFY)
     94     target_link_libraries(tests haskellsecp256k1_v0_1_0_precomputed haskellsecp256k1_v0_1_0_asm)
     95     add_test(NAME tests COMMAND tests)
     96   endif()
     97 endif()
     98 
     99 if(SECP256K1_BUILD_EXHAUSTIVE_TESTS)
    100   # Note: do not include haskellsecp256k1_v0_1_0_precomputed in exhaustive_tests (it uses runtime-generated tables).
    101   add_executable(exhaustive_tests tests_exhaustive.c)
    102   target_link_libraries(exhaustive_tests haskellsecp256k1_v0_1_0_asm)
    103   target_compile_definitions(exhaustive_tests PRIVATE $<$<NOT:$<CONFIG:Coverage>>:VERIFY>)
    104   add_test(NAME exhaustive_tests COMMAND exhaustive_tests)
    105 endif()
    106 
    107 if(SECP256K1_BUILD_CTIME_TESTS)
    108   add_executable(ctime_tests ctime_tests.c)
    109   target_link_libraries(ctime_tests secp256k1)
    110 endif()
    111 
    112 if(SECP256K1_INSTALL)
    113   install(TARGETS secp256k1
    114     EXPORT ${PROJECT_NAME}-targets
    115     RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    116     LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    117     ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    118   )
    119   set(${PROJECT_NAME}_headers
    120     "${PROJECT_SOURCE_DIR}/include/secp256k1.h"
    121     "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_preallocated.h"
    122   )
    123   if(SECP256K1_ENABLE_MODULE_ECDH)
    124     list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_ecdh.h")
    125   endif()
    126   if(SECP256K1_ENABLE_MODULE_RECOVERY)
    127     list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_recovery.h")
    128   endif()
    129   if(SECP256K1_ENABLE_MODULE_EXTRAKEYS)
    130     list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_extrakeys.h")
    131   endif()
    132   if(SECP256K1_ENABLE_MODULE_SCHNORRSIG)
    133     list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_schnorrsig.h")
    134   endif()
    135   if(SECP256K1_ENABLE_MODULE_ELLSWIFT)
    136     list(APPEND ${PROJECT_NAME}_headers "${PROJECT_SOURCE_DIR}/include/haskellsecp256k1_v0_1_0_ellswift.h")
    137   endif()
    138   install(FILES ${${PROJECT_NAME}_headers}
    139     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
    140   )
    141 
    142   install(EXPORT ${PROJECT_NAME}-targets
    143     FILE ${PROJECT_NAME}-targets.cmake
    144     NAMESPACE ${PROJECT_NAME}::
    145     DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
    146   )
    147 
    148   include(CMakePackageConfigHelpers)
    149   configure_package_config_file(
    150     ${PROJECT_SOURCE_DIR}/cmake/config.cmake.in
    151     ${PROJECT_NAME}-config.cmake
    152     INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
    153     NO_SET_AND_CHECK_MACRO
    154   )
    155   write_basic_package_version_file(${PROJECT_NAME}-config-version.cmake
    156     COMPATIBILITY SameMinorVersion
    157   )
    158 
    159   install(
    160     FILES
    161       ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config.cmake
    162       ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake
    163     DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
    164   )
    165 
    166   include(GeneratePkgConfigFile)
    167   generate_pkg_config_file(${PROJECT_SOURCE_DIR}/libsecp256k1.pc.in)
    168   install(
    169     FILES
    170       ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}.pc
    171     DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
    172   )
    173 endif()