1
0

CMakeLists.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  14. include(MakeTable.cmake) # generates Table.h
  15. # library that just does sqrt
  16. add_library(SqrtLibrary STATIC
  17. mysqrt.cxx
  18. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  19. )
  20. # state that we depend on our binary dir to find Table.h
  21. target_include_directories(SqrtLibrary PRIVATE
  22. ${CMAKE_CURRENT_BINARY_DIR}
  23. )
  24. # state that SqrtLibrary need PIC when the default is shared libraries
  25. set_target_properties(SqrtLibrary PROPERTIES
  26. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  27. )
  28. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  29. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  30. endif()
  31. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  32. # define the symbol stating we are using the declspec(dllexport) when
  33. # building on windows
  34. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  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}
  41. EXPORT MathFunctionsTargets
  42. DESTINATION lib)
  43. # install include headers
  44. install(FILES MathFunctions.h DESTINATION include)