1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2026-07-18 00:34:13 -04:00
Files
sdrangel/cmake/Modules/FindCodec2.cmake
T
Robin Getz 6b353ffd1c cmake: verify minimum codec2 version during discovery
Use pkg-config to verify that codec2 >= 1.1.1 is available before
searching for the headers and library.

If CODEC2_DIR is specified, treat it as an explicit user override and
search that installation directly. Otherwise, use pkg-config to validate
the minimum supported version. If pkg-config is unavailable or an older
codec2 version is installed, disable codec2 support while allowing the
rest of the project to configure normally.

Also update the pkg-config search hints to use the documented
PC_CODEC2_INCLUDE_DIRS and PC_CODEC2_LIBRARY_DIRS variables.

Signed-off-by: Robin Getz <rgetz503@gmail.com>
2026-07-10 20:32:52 -04:00

56 lines
1.9 KiB
CMake

# If CODEC2_DIR is specified, treat it as an explicit user override and
# search that installation directly. Otherwise use pkg-config to verify
# the minimum supported codec2 version before locating the headers and
# library.
if (NOT CODEC2_FOUND)
if (CODEC2_DIR)
message(STATUS "Using CODEC2_DIR: ${CODEC2_DIR}")
else()
find_package(PkgConfig QUIET)
if(NOT PKG_CONFIG_FOUND)
message(STATUS "codec2 support disabled: pkg-config is required to verify codec2 version.")
return()
endif()
pkg_check_modules(PC_CODEC2 QUIET codec2>=1.1.1)
if(NOT PC_CODEC2_FOUND)
message(STATUS "codec2 support disabled: codec2 >= 1.1.1 was not found.")
return()
endif()
endif()
FIND_PATH(CODEC2_INCLUDE_DIR
NAMES codec2/codec2.h
HINTS ${CODEC2_DIR}/include
${PC_CODEC2_INCLUDE_DIRS}
${CMAKE_INSTALL_PREFIX}/include
PATHS /usr/local/include
/usr/include
)
FIND_LIBRARY(CODEC2_LIBRARIES
NAMES codec2 libcodec2
HINTS ${CODEC2_DIR}/lib
${CODEC2_DIR}/lib64
${PC_CODEC2_LIBRARY_DIRS}
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib64
PATHS /usr/local/lib
/usr/local/lib64
/usr/lib
/usr/lib64
)
if(CODEC2_INCLUDE_DIR AND CODEC2_LIBRARIES)
set(CODEC2_FOUND TRUE CACHE INTERNAL "CODEC2 found")
message(STATUS "Found Codec2: ${CODEC2_INCLUDE_DIR}, ${CODEC2_LIBRARIES}")
else()
set(CODEC2_FOUND FALSE CACHE INTERNAL "CODEC2 found")
message(STATUS "Codec2 not found")
endif()
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(CODEC2 DEFAULT_MSG CODEC2_LIBRARIES CODEC2_INCLUDE_DIR)
MARK_AS_ADVANCED(CODEC2_LIBRARIES CODEC2_INCLUDE_DIR)
endif (NOT CODEC2_FOUND)