CMakeLists.txt 2.1 KB

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