CMakeLists.txt 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # state that SqrtLibrary need PIC when the default is shared libraries
  34. set_target_properties(SqrtLibrary PROPERTIES
  35. POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
  36. )
  37. target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
  38. endif()
  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. # install rules
  43. install(TARGETS MathFunctions DESTINATION lib)
  44. install(FILES MathFunctions.h DESTINATION include)