Skip to content

Commit

Permalink
Use FindPython to find the correct Python in a non-distro specific ma…
Browse files Browse the repository at this point in the history
…nner.
  • Loading branch information
tmiw committed Sep 27, 2024
1 parent cec7210 commit 323a49a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
19 changes: 8 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,14 @@ endif("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
# Set default flags (from opus-ng build)
set(CMAKE_C_FLAGS "-O2 -fvisibility=hidden -fstack-protector-strong -W -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wstrict-prototypes")

# Python tells us the CFLAGS we need for Embedding Python in a C lib
# The default PYTHON_CONFIG works on Ubuntu 22 but will likely need to be changed for other distros
if(NOT PYTHON_CONFIG)
set(PYTHON_CONFIG python3.10-config)
endif()
execute_process(COMMAND ${PYTHON_CONFIG} --cflags OUTPUT_VARIABLE PYTHON_C_FLAGS OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${PYTHON_CONFIG} --ldflags --embed OUTPUT_VARIABLE PYTHON_LD_LIBS OUTPUT_STRIP_TRAILING_WHITESPACE)
string(STRIP ${PYTHON_C_FLAGS} PYTHON_C_FLAGS)
string(STRIP ${PYTHON_LD_LIBS} PYTHON_LD_LIBS)
message(PYTHON_C_FLAGS="${PYTHON_C_FLAGS}")
message(PYTHON_LD_LIBS="${PYTHON_LD_LIBS}")
# Python tells us the CFLAGS we need for Embedding Python in a C lib.
# We also need to make sure we select the libraries in any activated venv first,
# in case the user is using that for e.g. NumPy/PyTorch.
set(Python3_FIND_STRATEGY LOCATION)
set(Python_FIND_REGISTRY LAST)
set(CMAKE_FIND_FRAMEWORK LAST)
find_package(Python3 COMPONENTS Interpreter Development NumPy REQUIRED)

add_subdirectory(src)

# Ctests ----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ add_executable(lpcnet_demo lpcnet_demo.c)
target_link_libraries(lpcnet_demo opus m)

add_executable(radae_tx radae_tx.c rade_api.c)
set_source_files_properties(rade_api.c PROPERTIES COMPILE_FLAGS "${PYTHON_C_FLAGS}")
target_link_libraries(radae_tx ${PYTHON_LD_LIBS})
#set_source_files_properties(rade_api.c PROPERTIES COMPILE_FLAGS "${PYTHON_C_FLAGS}")
target_link_libraries(radae_tx Python3::Python Python3::NumPy)

add_executable(radae_rx radae_rx.c rade_api.c)
target_link_libraries(radae_rx ${PYTHON_LD_LIBS})
target_link_libraries(radae_rx Python3::Python Python3::NumPy)

0 comments on commit 323a49a

Please sign in to comment.