Check if -lm is needed
@@ -2,6 +2,7 @@ set(SOURCES cbor.c cbor/streaming.c cbor/internal/encoders.c cbor/internal/build
include(GNUInstallDirs)
include(JoinPaths)
+include(CheckFunctionExists)
set(CMAKE_SKIP_BUILD_RPATH FALSE)
if (CBOR_CUSTOM_ALLOC)
@@ -14,7 +15,12 @@ endif()
add_library(cbor ${SOURCES})
target_include_directories(cbor PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
+
+# Explicitly link math.h if necessary
+check_function_exists(ldexp LDEXP_AVAILABLE)
+if (NOT LDEXP_AVAILABLE)
target_link_libraries(cbor m)
+endif()
include(GenerateExportHeader)
generate_export_header(cbor EXPORT_FILE_NAME ${CMAKE_CURRENT_BINARY_DIR}/cbor/cbor_export.h)
