CMakeLists.txt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. add_library(MathFunctions MathFunctions.cxx)
  2. # should we use our own math functions
  3. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  4. if (USE_MYMATH)
  5. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  6. # library that just does sqrt
  7. add_library(SqrtLibrary STATIC
  8. mysqrt.cxx
  9. )
  10. # link SqrtLibrary to tutorial_compiler_flags
  11. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  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. # add compile definitions
  29. if(HAVE_LOG AND HAVE_EXP)
  30. target_compile_definitions(SqrtLibrary
  31. PRIVATE "HAVE_LOG" "HAVE_EXP"
  32. )
  33. endif()
  34. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  35. endif()
  36. # state that anybody linking to us needs to include the current source dir
  37. # to find MathFunctions.h, while we don't.
  38. target_include_directories(MathFunctions
  39. INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
  40. )
  41. # link MathFunctions to tutorial_compiler_flags
  42. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  43. # install libs
  44. set(installable_libs MathFunctions tutorial_compiler_flags)
  45. if(TARGET SqrtLibrary)
  46. list(APPEND installable_libs SqrtLibrary)
  47. endif()
  48. install(TARGETS ${installable_libs} DESTINATION lib)
  49. # install include headers
  50. install(FILES MathFunctions.h DESTINATION include)