Imported Upstream version 3.25.0
[platform/upstream/cmake.git] / Help / guide / tutorial / Step8 / MathFunctions / CMakeLists.txt
1 add_library(MathFunctions mysqrt.cxx)
2
3 # state that anybody linking to us needs to include the current source dir
4 # to find MathFunctions.h, while we don't.
5 target_include_directories(MathFunctions
6           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
7           )
8
9 # link our compiler flags interface library
10 target_link_libraries(MathFunctions tutorial_compiler_flags)
11
12 # does this system provide the log and exp functions?
13 include(CheckCXXSourceCompiles)
14 check_cxx_source_compiles("
15   #include <cmath>
16   int main() {
17     std::log(1.0);
18     return 0;
19   }
20 " HAVE_LOG)
21 check_cxx_source_compiles("
22   #include <cmath>
23   int main() {
24     std::exp(1.0);
25     return 0;
26   }
27 " HAVE_EXP)
28
29 # add compile definitions
30 if(HAVE_LOG AND HAVE_EXP)
31   target_compile_definitions(MathFunctions
32                              PRIVATE "HAVE_LOG" "HAVE_EXP")
33 endif()
34
35 # install libs
36 set(installable_libs MathFunctions tutorial_compiler_flags)
37 install(TARGETS ${installable_libs} DESTINATION lib)
38 # install include headers
39 install(FILES MathFunctions.h DESTINATION include)