CMakeLists.txt 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. # first we add the executable that generates the table
  15. add_executable(MakeTable MakeTable.cxx)
  16. target_link_libraries(MakeTable PRIVATE tutorial_compiler_flags)
  17. # add the command to generate the source code
  18. add_custom_command(
  19. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  20. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  21. DEPENDS MakeTable
  22. )
  23. # library that just does sqrt
  24. add_library(SqrtLibrary STATIC
  25. mysqrt.cxx
  26. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  27. )
  28. # state that we depend on our binary dir to find Table.h
  29. target_include_directories(SqrtLibrary PRIVATE
  30. ${CMAKE_CURRENT_BINARY_DIR}
  31. )
  32. # state that SqrtLibrary need PIC when the default is shared libraries
  33. set_target_properties(SqrtLibrary PROPERTIES
  34. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  35. )
  36. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  37. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  38. endif()
  39. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  40. # define the symbol stating we are using the declspec(dllexport) when
  41. # building on windows
  42. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  43. # install libs
  44. set(installable_libs MathFunctions tutorial_compiler_flags)
  45. if(TARGET SqrtLibrary)
  46. list(APPEND installable_libs SqrtLibrary)
  47. endif()
  48. install(TARGETS ${installable_libs}
  49. EXPORT MathFunctionsTargets
  50. DESTINATION lib)
  51. # install include headers
  52. install(FILES MathFunctions.h DESTINATION include)