1
0

CMakeLists.txt 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. # first we add the executable that generates the table
  12. add_executable(MakeTable MakeTable.cxx)
  13. target_link_libraries(MakeTable tutorial_compiler_flags)
  14. # add the command to generate the source code
  15. add_custom_command(
  16. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  17. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  18. DEPENDS MakeTable
  19. )
  20. # library that just does sqrt
  21. add_library(SqrtLibrary STATIC
  22. mysqrt.cxx
  23. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  24. )
  25. # state that we depend on our binary dir to find Table.h
  26. target_include_directories(SqrtLibrary PRIVATE
  27. ${CMAKE_CURRENT_BINARY_DIR}
  28. )
  29. set_target_properties(SqrtLibrary PROPERTIES
  30. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  31. )
  32. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  33. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  34. if(HAVE_LOG AND HAVE_EXP)
  35. target_compile_definitions(SqrtLibrary
  36. PRIVATE "HAVE_LOG" "HAVE_EXP")
  37. endif()
  38. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  39. endif()
  40. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  41. # define the symbol stating we are using the declspec(dllexport) when
  42. #building on windows
  43. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  44. # install rules
  45. install(TARGETS MathFunctions DESTINATION lib)
  46. install(FILES MathFunctions.h DESTINATION include)