From b66f4b7129d93582f758697df0eb9be7ba6981d2 Mon Sep 17 00:00:00 2001 From: Claire's Monster Date: Sun, 30 Jun 2024 11:49:21 -0500 Subject: [PATCH] MNT: cmake patches (#170) * 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 ... --- cm_library_c_binding/CMakeLists.txt | 1 + cm_library_cffi_headers/compose_cffi_headers.py | 2 +- cm_python_module/CMakeLists.txt | 11 +++++++++-- cmake/SetSystemLibIfExists.cmake | 8 ++++---- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cm_library_c_binding/CMakeLists.txt b/cm_library_c_binding/CMakeLists.txt index fc5afed48..c61c32948 100644 --- a/cm_library_c_binding/CMakeLists.txt +++ b/cm_library_c_binding/CMakeLists.txt @@ -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) diff --git a/cm_library_cffi_headers/compose_cffi_headers.py b/cm_library_cffi_headers/compose_cffi_headers.py index d43c902ad..b1980057a 100644 --- a/cm_library_cffi_headers/compose_cffi_headers.py +++ b/cm_library_cffi_headers/compose_cffi_headers.py @@ -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): diff --git a/cm_python_module/CMakeLists.txt b/cm_python_module/CMakeLists.txt index 3919e7f47..c73cc6371 100644 --- a/cm_python_module/CMakeLists.txt +++ b/cm_python_module/CMakeLists.txt @@ -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() diff --git a/cmake/SetSystemLibIfExists.cmake b/cmake/SetSystemLibIfExists.cmake index 23a1a71b2..a965044d0 100644 --- a/cmake/SetSystemLibIfExists.cmake +++ b/cmake/SetSystemLibIfExists.cmake @@ -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()