CMakeLists.txt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  12. include(MakeTable.cmake) # generates Table.h
  13. # library that just does sqrt
  14. add_library(SqrtLibrary STATIC
  15. mysqrt.cxx
  16. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  17. )
  18. # state that we depend on our binary dir to find Table.h
  19. target_include_directories(SqrtLibrary PRIVATE
  20. ${CMAKE_CURRENT_BINARY_DIR}
  21. )
  22. # state that SqrtLibrary need PIC when the default is shared libraries
  23. set_target_properties(SqrtLibrary PROPERTIES
  24. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  25. )
  26. # link SqrtLibrary to tutorial_compiler_flags
  27. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  28. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  29. endif()
  30. # link MathFunctions to tutorial_compiler_flags
  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} DESTINATION lib)
  41. # install include headers
  42. install(FILES MathFunctions.h DESTINATION include)