CMakeLists.txt 1.9 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
  7. $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  8. $<INSTALL_INTERFACE:include>
  9. )
  10. # should we use our own math functions
  11. option(USE_MYMATH "Use tutorial provided math implementation" ON)
  12. if(USE_MYMATH)
  13. # first we add the executable that generates the table
  14. add_executable(MakeTable MakeTable.cxx)
  15. # add the command to generate the source code
  16. add_custom_command(
  17. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  18. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  19. DEPENDS MakeTable
  20. )
  21. # library that just does sqrt
  22. add_library(SqrtLibrary STATIC
  23. mysqrt.cxx
  24. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  25. )
  26. # state that we depend on our binary dir to find Table.h
  27. target_include_directories(SqrtLibrary PRIVATE
  28. ${CMAKE_CURRENT_BINARY_DIR}
  29. )
  30. set_target_properties(SqrtLibrary PROPERTIES
  31. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  32. )
  33. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  34. endif()
  35. target_compile_definitions(MathFunctions PRIVATE "$<$<BOOL:${USE_MYMATH}>:USE_MYMATH>")
  36. # define the symbol stating we are using the declspec(dllexport) when
  37. # building on windows
  38. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  39. # setup the version numbering
  40. set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
  41. set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
  42. # install rules
  43. install(TARGETS MathFunctions
  44. DESTINATION lib
  45. EXPORT MathFunctionsTargets)
  46. install(FILES MathFunctions.h DESTINATION include)