Skip to content

Commit e45da76

Browse files
authored
CMake: Detect libm with find_library (#596)
1 parent 78b1be3 commit e45da76

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ include (CheckTypeSize)
8080
include (CheckCCompilerFlag)
8181
include (CheckCXXSymbolExists)
8282
include (CheckCSourceCompiles)
83-
include (CheckCXXCompilerFlag)
84-
include (CheckLibraryExists)
8583

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

111-
check_library_exists ("m" sqrt "" HAVE_LIBM)
112-
if (HAVE_LIBM)
113-
set (M_LIBRARY m)
109+
find_library(M_LIBRARY m)
110+
if (M_LIBRARY)
114111
set (LIBS_PRIVATE "-l${M_LIBRARY}")
115112
endif()
116113

@@ -258,7 +255,9 @@ if (NLOPT_LUKSAN)
258255
target_include_directories(${nlopt_lib} PRIVATE src/algs/luksan)
259256
target_compile_definitions (${nlopt_lib} PRIVATE NLOPT_LUKSAN)
260257
endif ()
261-
target_link_libraries (${nlopt_lib} ${M_LIBRARY})
258+
if (M_LIBRARY)
259+
target_link_libraries (${nlopt_lib} ${M_LIBRARY})
260+
endif ()
262261
set_target_properties (${nlopt_lib} PROPERTIES SOVERSION ${SO_MAJOR})
263262
set_target_properties (${nlopt_lib} PROPERTIES VERSION "${SO_MAJOR}.${SO_MINOR}.${SO_PATCH}")
264263

0 commit comments

Comments
 (0)