Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: cmake patches #170

Merged
merged 17 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
Loading