CMakeLists.txt 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. # does this system provide the log and exp functions?
  14. include(CheckSymbolExists)
  15. set(CMAKE_REQUIRED_LIBRARIES "m")
  16. check_symbol_exists(log "math.h" HAVE_LOG)
  17. check_symbol_exists(exp "math.h" HAVE_EXP)
  18. # first we add the executable that generates the table
  19. add_executable(MakeTable MakeTable.cxx)
  20. target_link_libraries(MakeTable tutorial_compiler_flags)
  21. # add the command to generate the source code
  22. add_custom_command(
  23. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  24. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  25. DEPENDS MakeTable
  26. )
  27. # library that just does sqrt
  28. add_library(SqrtLibrary STATIC
  29. mysqrt.cxx
  30. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  31. )
  32. # state that we depend on our binary dir to find Table.h
  33. target_include_directories(SqrtLibrary PRIVATE
  34. ${CMAKE_CURRENT_BINARY_DIR}
  35. )
  36. set_target_properties(SqrtLibrary PROPERTIES
  37. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  38. )
  39. target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
  40. target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
  41. if(HAVE_LOG AND HAVE_EXP)
  42. target_compile_definitions(SqrtLibrary
  43. PRIVATE "HAVE_LOG" "HAVE_EXP")
  44. endif()
  45. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  46. endif()
  47. target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
  48. # define the symbol stating we are using the declspec(dllexport) when
  49. # building on windows
  50. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  51. # setup the version numbering
  52. set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
  53. set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
  54. # install rules
  55. install(TARGETS MathFunctions tutorial_compiler_flags
  56. DESTINATION lib
  57. EXPORT MathFunctionsTargets)
  58. install(FILES MathFunctions.h DESTINATION include)