CMakeLists.txt 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. # first we add the executable that generates the table
  13. add_executable(MakeTable MakeTable.cxx)
  14. target_link_libraries(MakeTable PRIVATE tutorial_compiler_flags)
  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. # state that SqrtLibrary need PIC when the default is shared libraries
  31. set_target_properties(SqrtLibrary PROPERTIES
  32. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  33. )
  34. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  35. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  36. endif()
  37. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  38. # define the symbol stating we are using the declspec(dllexport) when
  39. # building on windows
  40. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  41. # install rules
  42. set(installable_libs MathFunctions tutorial_compiler_flags)
  43. if(TARGET SqrtLibrary)
  44. list(APPEND installable_libs SqrtLibrary)
  45. endif()
  46. install(TARGETS ${installable_libs} DESTINATION lib)
  47. install(FILES MathFunctions.h DESTINATION include)