<div dir="ltr"><div dir="ltr"><div>Usually you don't need to use the full path to libm, and it's only needed sometimes depending on your compiler and toolchain.  I typically use something like the following to deal with both the implicit and explicit scenarios:</div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">include(CheckCSourceCompiles)<br>set(LIBM_TEST_SOURCE "#include<math.h>\nfloat f; int main(){sqrt(f);return 0;}")<br>check_c_source_compiles("${LIBM_TEST_SOURCE}" HAVE_MATH)<br>if(HAVE_MATH)</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">  set(LIBM_LIBRARIES)</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">else()<br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">  set(CMAKE_REQUIRED_LIBRARIES m)<br>  check_c_source_compiles("${LIBM_TEST_SOURCE}" HAVE_LIBM_MATH)<br>  unset(CMAKE_REQUIRED_LIBRARIES)<br>  if(NOT HAVE_LIBM_MATH)<br>    message(FATAL_ERROR "Unable to use C math library functions")<br>  endif()</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">  set(LIBM_LIBRARIES m)<br>endif()</span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace"><br></span></div><div style="margin-left:40px"><span style="font-family:monospace,monospace">target_link_libraries(fooTarget PRIVATE ${LIBM_LIBRARIES})</span></div><div><br></div><div><div><div dir="ltr" class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><div dir="ltr">----------<br>Chuck Atkins<br>Staff R&D Engineer, Scientific Computing<br>Kitware, Inc.<br><br></div></div></div></div></div></div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 15, 2019 at 7:46 AM frodak17 <<a href="mailto:frodak17@gmail.com">frodak17@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Mar 14, 2019 at 8:53 PM <a href="mailto:Workbench@gmx.at" target="_blank">Workbench@gmx.at</a> <<a href="mailto:workbench@gmx.at" target="_blank">workbench@gmx.at</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi everyone,<br>
<br>
i'm searching for a way to find the right include dir so that -lm can be<br>
found, the is not find_package for this, is /usr/lib and /usr/include a<br>
default because he find it without me adding any include or lib path for<br>
the build.<br>
<br>
<br></blockquote><div><br></div><div>It seems strange that you need to do this.  In my experience 'm' is just the math portion of the 'c' library.  Depending on which host and toolset you are using there can be multiple version of the 'm' library depending on target architecture and other options used.  The linker should just use the correct 'm' library just as it uses the correct 'c' library.  It could be in /usr/lib depending on how the compiler was packaged for your host. <br></div></div></div>
-- <br>
<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" rel="noreferrer" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br>
<br>
Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br>
<br>
CMake Support: <a href="http://cmake.org/cmake/help/support.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/support.html</a><br>
CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>
CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" rel="noreferrer" target="_blank">http://cmake.org/cmake/help/training.html</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="https://cmake.org/mailman/listinfo/cmake" rel="noreferrer" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><br>
</blockquote></div>