CMakeLists.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # first we add the executable that generates the table
  14. add_executable(MakeTable MakeTable.cxx)
  15. target_link_libraries(MakeTable tutorial_compiler_flags)
  16. # add the command to generate the source code
  17. add_custom_command(
  18. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  19. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  20. DEPENDS MakeTable
  21. )
  22. # library that just does sqrt
  23. add_library(SqrtLibrary STATIC
  24. mysqrt.cxx
  25. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  26. )
  27. # state that we depend on our binary dir to find Table.h
  28. target_include_directories(SqrtLibrary PRIVATE
  29. ${CMAKE_CURRENT_BINARY_DIR}
  30. )
  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_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  36. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  37. endif()
  38. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  39. # define the symbol stating we are using the declspec(dllexport) when
  40. # building on windows
  41. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  42. # setup the version numbering
  43. set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
  44. set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
  45. # install rules
  46. install(TARGETS MathFunctions tutorial_compiler_flags
  47. DESTINATION lib
  48. EXPORT MathFunctionsTargets)
  49. install(FILES MathFunctions.h DESTINATION include)