CMakeLists.txt 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # add the command to generate the source code
  21. add_custom_command(
  22. OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  23. COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  24. DEPENDS MakeTable
  25. )
  26. # library that just does sqrt
  27. add_library(SqrtLibrary STATIC
  28. mysqrt.cxx
  29. ${CMAKE_CURRENT_BINARY_DIR}/Table.h
  30. )
  31. # state that we depend on our binary dir to find Table.h
  32. target_include_directories(SqrtLibrary PRIVATE
  33. ${CMAKE_CURRENT_BINARY_DIR}
  34. )
  35. set_target_properties(SqrtLibrary PROPERTIES
  36. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  37. )
  38. target_compile_definitions(SqrtLibrary PRIVATE
  39. "$<$<BOOL:${HAVE_LOG}>:HAVE_LOG>"
  40. "$<$<BOOL:${HAVE_EXP}>:HAVE_EXP>"
  41. )
  42. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  43. endif()
  44. target_compile_definitions(MathFunctions PRIVATE "$<$<BOOL:${USE_MYMATH}>:USE_MYMATH>")
  45. # define the symbol stating we are using the declspec(dllexport) when
  46. # building on windows
  47. target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
  48. # setup the version numbering
  49. set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
  50. set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
  51. install(TARGETS MathFunctions
  52. DESTINATION lib
  53. EXPORT MathFunctionsTargets)
  54. install(FILES MathFunctions.h DESTINATION include)