CMakeLists.txt 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. # first we add the executable that generates the table
  12. add_executable(MakeTable MakeTable.cxx)
  13. # add the command to generate the source code
  14. add_custom_command(
  15. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  16. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  17. DEPENDS MakeTable
  18. )
  19. # library that just does sqrt
  20. add_library(SqrtLibrary STATIC
  21. mysqrt.cxx
  22. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  23. )
  24. # state that we depend on our binary dir to find Table.h
  25. target_include_directories(SqrtLibrary PRIVATE
  26. ${CMAKE_CURRENT_BINARY_DIR}
  27. )
  28. # state that SqrtLibrary need PIC when the default is shared libraries
  29. set_target_properties(SqrtLibrary PROPERTIES
  30. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  31. )
  32. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  33. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  34. endif()
  35. # define the symbol stating we are using the declspec(dllexport) when
  36. # building on windows
  37. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  38. # install rules
  39. install(TARGETS MathFunctions DESTINATION lib)
  40. install(FILES MathFunctions.h DESTINATION include)