CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # add the library that runs
  2. add_library(MathFunctions MathFunctions.cxx)
  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. # should we use our own math functions
  9. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  10. if(USE_MYMATH)
  11. # does this system provide the log and exp functions?
  12. include(CheckSymbolExists)
  13. set(CMAKE_REQUIRED_LIBRARIES "m")
  14. check_symbol_exists(log "math.h" HAVE_LOG)
  15. check_symbol_exists(exp "math.h" HAVE_EXP)
  16. # first we add the executable that generates the table
  17. add_executable(MakeTable MakeTable.cxx)
  18. target_link_libraries(MakeTable tutorial_compiler_flags)
  19. # add the command to generate the source code
  20. add_custom_command(
  21. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  22. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  23. DEPENDS MakeTable
  24. )
  25. # library that just does sqrt
  26. add_library(SqrtLibrary STATIC
  27. mysqrt.cxx
  28. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  29. )
  30. # state that we depend on our binary dir to find Table.h
  31. target_include_directories(SqrtLibrary PRIVATE
  32. ${CMAKE_CURRENT_BINARY_DIR}
  33. )
  34. set_target_properties(SqrtLibrary PROPERTIES
  35. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  36. )
  37. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  38. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  39. if(HAVE_LOG AND HAVE_EXP)
  40. target_compile_definitions(SqrtLibrary
  41. PRIVATE "HAVE_LOG" "HAVE_EXP")
  42. endif()
  43. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  44. endif()
  45. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  46. # define the symbol stating we are using the declspec(dllexport) when
  47. #building on windows
  48. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  49. # install rules
  50. install(TARGETS MathFunctions DESTINATION lib)
  51. install(FILES MathFunctions.h DESTINATION include)