diff --git a/CMakeLists.txt b/CMakeLists.txt index 62791184..e1014123 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -432,6 +432,27 @@ if(HAMLIB_LIBRARY AND HAMLIB_INCLUDE_DIR) message(STATUS "Hamlib library found.") include_directories(${HAMLIB_INCLUDE_DIR}) list(APPEND FREEDV_LINK_LIBS ${HAMLIB_LIBRARY}) + + # Special-case to determine whether the user is using Hamlib >=4.6. + # In 4.6, RIGCAPS_NO_CONST is no longer defined and causes compiler + # errors during build without special logic to handle this. This may + # also be true in 4.7 as the test script below prints 4.7~git on Fedora + # 42 as of 2025-06-15. + if (NOT CMAKE_CROSSCOMPILING) + try_run(HAMLIB_RUN_RESULT HAMLIB_COMPILE_RESULT + SOURCES ${CMAKE_SOURCE_DIR}/cmake/hamlib-test.c + CMAKE_FLAGS -DINCLUDE_DIRECTORIES=${HAMLIB_INCLUDE_DIR} + LINK_LIBRARIES ${HAMLIB_LIBRARY} + RUN_OUTPUT_VARIABLE HAMLIB_VERSION) + if (NOT HAMLIB_COMPILE_RESULT OR NOT HAMLIB_RUN_RESULT OR NOT HAMLIB_VERSION) + message(FATAL_ERROR "Could not determine Hamlib version.") + else() + if (NOT HAMLIB_VERSION STRLESS "Hamlib 4.6") + message(STATUS "Enabling Hamlib 4.6 compile workaround.") + add_definitions(-DHAMLIB_CONST_WORKAROUND) + endif (NOT HAMLIB_VERSION STRLESS "Hamlib 4.6") + endif (NOT HAMLIB_COMPILE_RESULT OR NOT HAMLIB_RUN_RESULT OR NOT HAMLIB_VERSION) + endif (NOT CMAKE_CROSSCOMPILING) else(HAMLIB_LIBRARY AND HAMLIB_INCLUDE_DIR) message(STATUS "Using own Hamlib build") include(cmake/BuildHamlib.cmake) diff --git a/USER_MANUAL.md b/USER_MANUAL.md index 2cb749fb..eb3804b0 100644 --- a/USER_MANUAL.md +++ b/USER_MANUAL.md @@ -805,6 +805,7 @@ LDPC | Low Density Parity Check Codes - a family of powerful FEC codes * FreeDV Reporter: Work around Linux bug preventing some flag emojis from being fully deleted on backspace. (PR #931) * Fix GTK+ assertion after FreeDV Reporter has been open for a long time. (PR #929) * Easy Setup: Use card names instead of device names for generating device list. (PR #932) + * Fix compiler error on Fedora 42 when using Hamlib packages. (PR #936) * Prevent real-time memory from being swapped by OS to reduce audio dropouts. (PR #933) 2. Documentation: * Add missing dependency for macOS builds to README. (PR #925; thanks @relistan!) diff --git a/cmake/hamlib-test.c b/cmake/hamlib-test.c new file mode 100644 index 00000000..50c6b309 --- /dev/null +++ b/cmake/hamlib-test.c @@ -0,0 +1,8 @@ +#include +#include + +int main() +{ + printf("%s", hamlib_version); + return 1; +} diff --git a/src/rig_control/HamlibRigController.cpp b/src/rig_control/HamlibRigController.cpp index d18f1540..b82b5157 100644 --- a/src/rig_control/HamlibRigController.cpp +++ b/src/rig_control/HamlibRigController.cpp @@ -37,11 +37,11 @@ HamlibRigController::RigList HamlibRigController::RigList_; HamlibRigController::RigNameList HamlibRigController::RigNameList_; std::mutex HamlibRigController::RigListMutex_; -#if RIGCAPS_NOT_CONST +#if RIGCAPS_NOT_CONST && !HAMLIB_CONST_WORKAROUND int HamlibRigController::BuildRigList_(struct rig_caps *rig, rig_ptr_t rigList) { #else int HamlibRigController::BuildRigList_(const struct rig_caps *rig, rig_ptr_t rigList) { -#endif // RIGCAPS_NOT_CONST +#endif // RIGCAPS_NOT_CONST && !HAMLIB_CONST_WORKAROUND ((HamlibRigController::RigList *)rigList)->push_back(rig); return 1; } diff --git a/src/rig_control/HamlibRigController.h b/src/rig_control/HamlibRigController.h index 0b7f6188..99bcb12f 100644 --- a/src/rig_control/HamlibRigController.h +++ b/src/rig_control/HamlibRigController.h @@ -107,11 +107,11 @@ private: static bool RigCompare_(const struct rig_caps *rig1, const struct rig_caps *rig2); -#if RIGCAPS_NOT_CONST +#if RIGCAPS_NOT_CONST && !HAMLIB_CONST_WORKAROUND static int BuildRigList_(struct rig_caps *rig, rig_ptr_t); #else static int BuildRigList_(const struct rig_caps *rig, rig_ptr_t); -#endif // RIGCAPS_NOT_CONST +#endif // RIGCAPS_NOT_CONST && !HAMLIB_CONST_WORKAROUND }; #endif // HAMLIB_RIG_CONTROLLER_H