| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 | # add the library that runsadd_library(MathFunctions MathFunctions.cxx)# state that anybody linking to us needs to include the current source dir# to find MathFunctions.h, while we don't.target_include_directories(MathFunctions                           INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}                           )# should we use our own math functionsoption(USE_MYMATH "Use tutorial provided math implementation" ON)if(USE_MYMATH)  target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")  # first we add the executable that generates the table  add_executable(MakeTable MakeTable.cxx)  # add the command to generate the source code  add_custom_command(    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h    COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h    DEPENDS MakeTable    )  # library that just does sqrt  add_library(SqrtLibrary STATIC              mysqrt.cxx              ${CMAKE_CURRENT_BINARY_DIR}/Table.h              )  # state that we depend on our binary dir to find Table.h  target_include_directories(SqrtLibrary PRIVATE                             ${CMAKE_CURRENT_BINARY_DIR}                             )  # state that SqrtLibrary need PIC when the default is shared libraries  set_target_properties(SqrtLibrary PROPERTIES                        POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}                        )  target_link_libraries(MathFunctions PRIVATE SqrtLibrary)endif()# define the symbol stating we are using the declspec(dllexport) when# building on windowstarget_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")# install rulesinstall(TARGETS MathFunctions DESTINATION lib)install(FILES MathFunctions.h DESTINATION include)
 |