1 # add the library that runs
2 add_library(MathFunctions MathFunctions.cxx)
4 # state that anybody linking to us needs to include the current source dir
5 # to find MathFunctions.h, while we don't.
6 target_include_directories(MathFunctions
8 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
9 $<INSTALL_INTERFACE:include>
12 # should we use our own math functions
13 option(USE_MYMATH "Use tutorial provided math implementation" ON)
16 target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
18 # first we add the executable that generates the table
19 add_executable(MakeTable MakeTable.cxx)
20 target_link_libraries(MakeTable PRIVATE tutorial_compiler_flags)
22 # add the command to generate the source code
24 OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
25 COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
29 # library that just does sqrt
30 add_library(SqrtLibrary STATIC
32 ${CMAKE_CURRENT_BINARY_DIR}/Table.h
35 # state that we depend on our binary dir to find Table.h
36 target_include_directories(SqrtLibrary PRIVATE
37 ${CMAKE_CURRENT_BINARY_DIR}
40 # state that SqrtLibrary need PIC when the default is shared libraries
41 set_target_properties(SqrtLibrary PROPERTIES
42 POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
45 target_link_libraries(SqrtLibrary PUBLIC tutorial_compiler_flags)
46 target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
49 target_link_libraries(MathFunctions PUBLIC tutorial_compiler_flags)
51 # define the symbol stating we are using the declspec(dllexport) when
53 target_compile_definitions(MathFunctions PRIVATE "EXPORTING_MYMATH")
55 # setup the version numbering
56 set_property(TARGET MathFunctions PROPERTY VERSION "1.0.0")
57 set_property(TARGET MathFunctions PROPERTY SOVERSION "1")
60 set(installable_libs MathFunctions tutorial_compiler_flags)
61 if(TARGET SqrtLibrary)
62 list(APPEND installable_libs SqrtLibrary)
64 install(TARGETS ${installable_libs}
65 EXPORT MathFunctionsTargets
67 # install include headers
68 install(FILES MathFunctions.h DESTINATION include)