CMakeLists.txt 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  11. # does this system provide the log and exp functions?
  12. include(CheckCXXSourceCompiles)
  13. check_cxx_source_compiles("
  14. #include <cmath>
  15. int main() {
  16. std::log(1.0);
  17. return 0;
  18. }
  19. " HAVE_LOG)
  20. check_cxx_source_compiles("
  21. #include <cmath>
  22. int main() {
  23. std::exp(1.0);
  24. return 0;
  25. }
  26. " HAVE_EXP)
  27. # add compile definitions
  28. if(HAVE_LOG AND HAVE_EXP)
  29. target_compile_definitions(SqrtLibrary
  30. PRIVATE "HAVE_LOG" "HAVE_EXP"
  31. )
  32. endif()
  33. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  34. endif()
  35. # state that anybody linking to us needs to include the current source dir
  36. # to find MathFunctions.h, while we don't.
  37. target_include_directories(MathFunctions
  38. INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
  39. )
  40. # link our compiler flags interface library
  41. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  42. # install libs
  43. set(installable_libs MathFunctions tutorial_compiler_flags)
  44. if(TARGET SqrtLibrary)
  45. list(APPEND installable_libs SqrtLibrary)
  46. endif()
  47. install(TARGETS ${installable_libs} DESTINATION lib)
  48. # install include headers
  49. install(FILES MathFunctions.h DESTINATION include)