CMakeLists.txt 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. # link SqrtLibrary to tutorial_compiler_flags
  29. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  30. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  31. endif()
  32. # link MathFunctions to tutorial_compiler_flags
  33. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  34. # define the symbol stating we are using the declspec(dllexport) when
  35. # building on windows
  36. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  37. # setup the version numbering
  38. set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
  39. set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
  40. # install libs
  41. set(installable_libs MathFunctions tutorial_compiler_flags)
  42. if(TARGET SqrtLibrary)
  43. list(APPEND installable_libs SqrtLibrary)
  44. endif()
  45. install(TARGETS ${installable_libs}
  46. EXPORT MathFunctionsTargets
  47. DESTINATION lib)
  48. # install include headers
  49. install(FILES MathFunctions.h DESTINATION include)