CMakeLists.txt 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  16. # TODO 1: Include CheckCXXSourceCompiles
  17. # TODO 2: Use check_cxx_source_compiles with simple C++ code to verify
  18. # availability of:
  19. # * std::log
  20. # * std::exp
  21. # Store the results in HAVE_LOG and HAVE_EXP respectively.
  22. # Hint: Sample C++ code which uses log:
  23. # #include <cmath>
  24. # int main() {
  25. # std::log(1.0);
  26. # return 0;
  27. # }
  28. # TODO 3: Conditionally on HAVE_LOG and HAVE_EXP, add private compile
  29. # definitions "HAVE_LOG" and "HAVE_EXP" to the SqrtLibrary target.
  30. # Hint: Use target_compile_definitions()
  31. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  32. endif()
  33. # link our compiler flags interface library
  34. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  35. # install libs
  36. set(installable_libs MathFunctions tutorial_compiler_flags)
  37. if(TARGET SqrtLibrary)
  38. list(APPEND installable_libs SqrtLibrary)
  39. endif()
  40. install(TARGETS ${installable_libs} DESTINATION lib)
  41. # install include headers
  42. install(FILES MathFunctions.h DESTINATION include)