CMakeLists.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. add_library(MathFunctions MathFunctions.cxx)
  2. # state that anybody linking to us needs to include the current source dir
  3. # to find MathFunctions.h, while we don't.
  4. target_include_directories(MathFunctions
  5. INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
  6. )
  7. # should we use our own math functions
  8. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  9. if (USE_MYMATH)
  10. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  11. # library that just does sqrt
  12. add_library(SqrtLibrary STATIC
  13. mysqrt.cxx
  14. )
  15. # link SqrtLibrary to tutorial_compiler_flags
  16. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  17. # TODO 1: Include CheckCXXSourceCompiles
  18. # TODO 2: Use check_cxx_source_compiles with simple C++ code to verify
  19. # availability of:
  20. # * std::log
  21. # * std::exp
  22. # Store the results in HAVE_LOG and HAVE_EXP respectively.
  23. # Hint: Sample C++ code which uses log:
  24. # #include <cmath>
  25. # int main() {
  26. # std::log(1.0);
  27. # return 0;
  28. # }
  29. # TODO 3: Conditionally on HAVE_LOG and HAVE_EXP, add private compile
  30. # definitions "HAVE_LOG" and "HAVE_EXP" to the SqrtLibrary target.
  31. # Hint: Use target_compile_definitions()
  32. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  33. endif()
  34. # link MathFunctions to tutorial_compiler_flags
  35. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  36. # install libs
  37. set(installable_libs MathFunctions tutorial_compiler_flags)
  38. if(TARGET SqrtLibrary)
  39. list(APPEND installable_libs SqrtLibrary)
  40. endif()
  41. install(TARGETS ${installable_libs} DESTINATION lib)
  42. # install include headers
  43. install(FILES MathFunctions.h DESTINATION include)