Skip to content

Commit

Permalink
MNT: cmake patches (#170)
Browse files Browse the repository at this point in the history
* FEAT: Update libsecp256k1 to v0.5.0

* (fix) used wrong zip SHA

* (ref) c-binding dependency on header

* (ref) python module dependency on c-binding dependency on header. workaround for windows mishandling of pkg-config flags

* (ref) simplify pkg-config path. add --msvc-syntax --dont-define-prefix

* (fix) ruff check

* (fix) still need to update github flow, tempted to remove it

* (fix) remove COINCURVE_UPSTREAM_REF from workflow

* (fix) remove COINCURVE_UPSTREAM_REF from workflow

* (fix) remove COINCURVE_UPSTREAM_REF from workflow - shared flow

* (fix) secp256k1 haeder dir for c-binding compilation

* (fix) secp256k1 haeder dir for c-binding compilation

* (fix) secp256k1 haeder dir for c-binding compilation

* (fix) inattention, missing separating line

* (fix) silly, copy-paste without updating the target to cffi-c-binding

* (fix) more silliness, updated wrong variables, etc ...
  • Loading branch information
MementoRC authored Jun 30, 2024
1 parent 36acb70 commit b66f4b7
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions cm_library_c_binding/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ add_custom_command(
)

add_custom_target(cffi-c-binding ALL DEPENDS ${CFFI_C_CODE_DIR}/${CFFI_C_CODE})
add_dependencies(cffi-c-binding headers-for-cffi)
2 changes: 1 addition & 1 deletion cm_library_cffi_headers/compose_cffi_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def remove_c_comments_emptylines(text):


def remove_c_includes(lines):
return [line for line in lines if not line.startswith('#include ')]
return [line for line in lines if not re.match(r'^\s*#include\s', line)]


def remove_special_defines(lines, defines):
Expand Down
11 changes: 9 additions & 2 deletions cm_python_module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@ if (PROJECT_IGNORE_SYSTEM_LIB OR NOT VENDORED_AS_SYSTEM_LIB_FOUND)
# https://docs.python.org/3/c-api/stable.html#limited-c-api
target_link_libraries(${CFFI_OUTPUT_LIBRARY} PRIVATE ${CFFI_INPUT_LIBRARY})
elseif(VENDORED_AS_SYSTEM_LIB_FOUND)
message(STATUS "Vendored system library found: ${VENDORED_AS_SYSTEM_LIB_LINK_LIBRARIES}")
message(STATUS "Vendored system library found: ${VENDORED_AS_SYSTEM_LIB_LIBRARIES}")
target_include_directories(${CFFI_OUTPUT_LIBRARY} PRIVATE ${VENDORED_AS_SYSTEM_LIB_INCLUDE_DIRS})
target_link_libraries(${CFFI_OUTPUT_LIBRARY} PRIVATE ${VENDORED_AS_SYSTEM_LIB_LDFLAGS})
add_dependencies(${CFFI_OUTPUT_LIBRARY} cffi-c-binding)
# On windows, using the LDFLAGS field creates /libpath... secp256k1.lib (correct), but at a later stage
# /libpath is converted to \libpath and fails to be interpreted as a flag by the linker
# This may be an issue with libsecp256k1.pc, i.e. wrong slash used that triggers the slash conversion
target_link_libraries(${CFFI_OUTPUT_LIBRARY} PRIVATE ${VENDORED_AS_SYSTEM_LIB_LIBRARIES})
string(REPLACE "/libpath:" "" VENDORED_AS_SYSTEM_LIB_LIBRARY_DIRS ${VENDORED_AS_SYSTEM_LIB_LIBRARY_DIRS})
string(REPLACE "/LIBPATH:" "" VENDORED_AS_SYSTEM_LIB_LIBRARY_DIRS ${VENDORED_AS_SYSTEM_LIB_LIBRARY_DIRS})
target_link_directories(${CFFI_OUTPUT_LIBRARY} PRIVATE ${VENDORED_AS_SYSTEM_LIB_LIBRARY_DIRS})
else()
message(FATAL_ERROR "Vendored library not found.")
endif()
Expand Down
8 changes: 4 additions & 4 deletions cmake/SetSystemLibIfExists.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function (SetSystemLibIfExists)
set(_paths "$ENV{PKG_CONFIG_PATH}" "$ENV{CONDA_PREFIX}/Library/lib/pkgconfig" "$ENV{CONDA_PREFIX}/lib/pkgconfig")
cmake_path(CONVERT "${_paths}" TO_NATIVE_PATH_LIST _paths)
set(ENV{PKG_CONFIG_PATH} ${_paths})

set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH};$ENV{CONDA_PREFIX}/Library/lib/pkgconfig;$ENV{CONDA_PREFIX}/lib/pkgconfig")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(PKG_CONFIG_EXECUTABLE "${PKG_CONFIG_EXECUTABLE};--msvc-syntax;--dont-define-prefix")
endif()
pkg_check_modules(VENDORED_AS_SYSTEM_LIB IMPORTED_TARGET GLOBAL ${VENDORED_LIBRARY_PKG_CONFIG}>=${VENDORED_LIBRARY_PKG_CONFIG_VERSION})
endfunction()

0 comments on commit b66f4b7

Please sign in to comment.