Fix installation issues from RT library cmake split
[dyninst.git] / CMakeLists.txt
1 if(UNIX)
2 cmake_minimum_required (VERSION 2.8.11)
3 else()
4 cmake_minimum_required (VERSION 2.6.4)
5 endif()
6 project (Dyninst)
7
8 set (DYNINST_ROOT ${PROJECT_SOURCE_DIR})
9
10 include (${DYNINST_ROOT}/cmake/shared.cmake)
11
12 if(${PLATFORM} MATCHES nt)
13 set (HEADER_DIRS common
14                  dataflowAPI
15                  dyninstAPI
16                  dynutil
17                  instructionAPI
18                  parseAPI
19                  patchAPI
20                  proccontrol
21                  stackwalk
22                  symtabAPI
23     )
24 else()
25 set (HEADER_DIRS common
26                  dataflowAPI
27                  dwarf
28                  dyninstAPI
29                  dynutil
30                  elf
31                  instructionAPI
32                  parseAPI
33                  patchAPI
34                  proccontrol
35                  stackwalk
36                  symlite
37                  symtabAPI
38     )
39 endif()
40
41 foreach (dir ${HEADER_DIRS})
42   include_directories ( ${DYNINST_ROOT}/${dir}/h )
43 endforeach()
44
45 include_directories (
46                     ${DYNINST_ROOT}
47                     ${DYNINST_ROOT}/external
48   )
49
50 # Component time
51 add_subdirectory (common)
52 if(NOT ${PLATFORM} MATCHES nt)
53     add_subdirectory (elf)
54     add_subdirectory (dwarf)
55     add_subdirectory (symlite)
56 endif()
57 add_subdirectory (instructionAPI)
58 add_subdirectory (symtabAPI)
59 add_subdirectory (parseAPI)
60 add_subdirectory (patchAPI)
61 add_subdirectory (proccontrol)
62 add_subdirectory (stackwalk)
63 add_subdirectory (dyninstAPI)
64
65 #Build the RT library as a seperate project so we can change compilers
66 set(RT_SOURCE_DIR ${DYNINST_ROOT}/dyninstAPI_RT)
67 set(RT_BINARY_DIR ${PROJECT_BINARY_DIR}/dyninstAPI_RT)
68 file(MAKE_DIRECTORY ${RT_BINARY_DIR})
69 if (PLATFORM MATCHES bgq)
70 set (RT_C_COMPILER mpicc)
71 else()
72 set (RT_C_COMPILER ${CMAKE_C_COMPILER})
73 endif()
74
75 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
76                 COMMAND ${CMAKE_COMMAND}
77                 -DCMAKE_C_COMPILER=${RT_C_COMPILER}
78                 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
79                 -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
80                 -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
81                 -DPLATFORM=${PLATFORM}
82                 ${RT_SOURCE_DIR})
83 add_custom_target(DyninstRT
84                   ALL
85                   COMMAND ${CMAKE_COMMAND} --build ${RT_BINARY_DIR} --config $<CONFIGURATION>
86                   COMMENT "Building DyninstRT"
87                   VERBATIM)
88 install(CODE "include(\"${RT_BINARY_DIR}/cmake_install.cmake\")")
89
90
91 if(UNIX)
92 add_dependencies(dynDwarf libdwarf_imp)
93 add_dependencies(dynElf libelf_imp)
94 if (NOT USE_GNU_DEMANGLER)
95 add_dependencies(common libiberty_imp)
96 endif()
97 add_dependencies(libdwarf_imp libelf_imp)
98 endif()
99
100 if(NOT ${PLATFORM} MATCHES nt)
101     SET_TARGET_PROPERTIES (
102         common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
103         patchAPI pcontrol stackwalk dyninstAPI
104         PROPERTIES
105             SOVERSION ${SOVERSION}
106             VERSION ${LIBVERSION}
107     )
108 else()
109     SET_TARGET_PROPERTIES (
110         common instructionAPI symtabAPI parseAPI
111         patchAPI pcontrol stackwalk dyninstAPI
112         PROPERTIES
113             SOVERSION ${SOVERSION}
114             VERSION ${LIBVERSION}
115     )
116
117 endif()
118
119 if(UNIX)
120 if(SHOULD_INSTALL_LIBELF)
121 get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
122 file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
123 message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
124 message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
125 install (FILES ${LIBELF_INSTALL_FILES}
126         DESTINATION "${INSTALL_LIB_DIR}")
127 endif()
128 if(NOT LIBDWARF_FOUND)
129 message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
130 install (FILES ${LIBDWARF_LIBRARIES}
131         DESTINATION "${INSTALL_LIB_DIR}")
132 endif()
133 endif()
134 install (FILES
135         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
136         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
137         DESTINATION "${INSTALL_CMAKE_DIR}")
138 install (EXPORT DyninstTargets
139         DESTINATION "${INSTALL_CMAKE_DIR}")
140
141 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
142
143 # And version file
144 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)