0bfe20c100288381a843125aa69372c08f98cba4
[platform/upstream/cmake.git] / Help / guide / tutorial / Step10 / MathFunctions / CMakeLists.txt
1 # add the library that runs
2 add_library(MathFunctions MathFunctions.cxx)
3
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
7                            INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}
8                            )
9
10 # should we use our own math functions
11 option(USE_MYMATH "Use tutorial provided math implementation" ON)
12 if(USE_MYMATH)
13
14   target_compile_definitions(MathFunctions PRIVATE "USE_MYMATH")
15
16   # first we add the executable that generates the table
17   add_executable(MakeTable MakeTable.cxx)
18
19   # add the command to generate the source code
20   add_custom_command(
21     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/Table.h
22     COMMAND MakeTable ${CMAKE_CURRENT_BINARY_DIR}/Table.h
23     DEPENDS MakeTable
24     )
25
26   # library that just does sqrt
27   add_library(SqrtLibrary STATIC
28               mysqrt.cxx
29               ${CMAKE_CURRENT_BINARY_DIR}/Table.h
30               )
31
32   # state that we depend on our binary dir to find Table.h
33   target_include_directories(SqrtLibrary PRIVATE
34                              ${CMAKE_CURRENT_BINARY_DIR}
35                              )
36
37   # state that SqrtLibrary need PIC when the default is shared libraries
38   set_target_properties(SqrtLibrary PROPERTIES
39                         POSITION_INDEPENDENT_CODE ${BUILD_SHARED_LIBS}
40                         )
41
42   target_link_libraries(MathFunctions PRIVATE SqrtLibrary)
43 endif()
44
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
49 # install rules
50 set(installable_libs MathFunctions)
51 if(TARGET SqrtLibrary)
52   list(APPEND installable_libs SqrtLibrary)
53 endif()
54 install(TARGETS ${installable_libs} DESTINATION lib)
55 install(FILES MathFunctions.h DESTINATION include)