Skip to content

Commit

Permalink
CMake: Detect libm with find_library (#596)
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller authored Feb 24, 2025
1 parent 78b1be3 commit e45da76
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ include (CheckTypeSize)
include (CheckCCompilerFlag)
include (CheckCXXSymbolExists)
include (CheckCSourceCompiles)
include (CheckCXXCompilerFlag)
include (CheckLibraryExists)

#==============================================================================
# COMPILATION CHECKINGS and CONFIGURATION GENERATION
Expand All @@ -108,9 +106,8 @@ set (HAVE_UINT32_T ${SIZEOF_UINT32_T})
check_type_size ("unsigned int" SIZEOF_UNSIGNED_INT)
check_type_size ("unsigned long" SIZEOF_UNSIGNED_LONG)

check_library_exists ("m" sqrt "" HAVE_LIBM)
if (HAVE_LIBM)
set (M_LIBRARY m)
find_library(M_LIBRARY m)
if (M_LIBRARY)
set (LIBS_PRIVATE "-l${M_LIBRARY}")
endif()

Expand Down Expand Up @@ -258,7 +255,9 @@ if (NLOPT_LUKSAN)
target_include_directories(${nlopt_lib} PRIVATE src/algs/luksan)
target_compile_definitions (${nlopt_lib} PRIVATE NLOPT_LUKSAN)
endif ()
target_link_libraries (${nlopt_lib} ${M_LIBRARY})
if (M_LIBRARY)
target_link_libraries (${nlopt_lib} ${M_LIBRARY})
endif ()
set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${SO_MAJOR})
set_target_properties (${nlopt_lib} PROPERTIES VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}")

Expand Down

0 comments on commit e45da76

Please sign in to comment.