Externalize dwarf/elf, search for PIC libiberty
[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_MAJOR_VERSION 8)
9 set (DYNINST_MINOR_VERSION 2)
10 set (DYNINST_PATCH_VERSION 0)
11
12 set (SOVERSION "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}")
13 set (LIBVERSION "${SOVERSION}.${DYNINST_PATCH_VERSION}")
14 set (DYNINST_VERSION "${LIBVERSION}")
15
16 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules")
17 include (cmake/platform.cmake)
18 include (cmake/packages.cmake)
19 include (cmake/cap_arch_def.cmake)
20 include (cmake/c++11.cmake)
21 include (cmake/warnings.cmake)
22 include (cmake/options.cmake)
23 include (cmake/optimization.cmake)
24
25 set (BUILD_SHARED_LIBS ON)
26
27 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
28 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
29 set (INSTALL_CMAKE_DIR lib/cmake/Dyninst CACHE PATH "Installation directory for CMake files")
30
31 # Make the above absolute paths if necessary
32 foreach (p LIB INCLUDE CMAKE)
33   set (var INSTALL_${p}_DIR)
34   if (NOT IS_ABSOLUTE "${${var}}")
35      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
36   endif()
37 endforeach()
38
39 include_directories (
40                     ${PROJECT_SOURCE_DIR}
41                     ${PROJECT_SOURCE_DIR}/external
42   )
43
44 if(${PLATFORM} MATCHES nt)
45 set (HEADER_DIRS common
46                  dataflowAPI
47                  dyninstAPI
48                  dyninstAPI_RT
49                  dynutil
50                  instructionAPI
51                  parseAPI
52                  patchAPI
53                  proccontrol
54                  stackwalk
55                  symtabAPI
56     )
57 else()
58 set (HEADER_DIRS common
59                  dataflowAPI
60                  dwarf
61                  dyninstAPI
62                  dyninstAPI_RT
63                  dynutil
64                  elf
65                  instructionAPI
66                  parseAPI
67                  patchAPI
68                  proccontrol
69                  stackwalk
70                  symlite
71                  symtabAPI
72     )
73 endif()
74
75 foreach (dir ${HEADER_DIRS})
76   include_directories ( ${PROJECT_SOURCE_DIR}/${dir}/h )
77 endforeach()
78
79 # Component time
80 add_subdirectory (common)
81 if(NOT ${PLATFORM} MATCHES nt)
82     add_subdirectory (elf)
83     add_subdirectory (dwarf)
84     add_subdirectory (symlite)
85 endif()
86 add_subdirectory (instructionAPI)
87 add_subdirectory (symtabAPI)
88 add_subdirectory (parseAPI)
89 add_subdirectory (patchAPI)
90 add_subdirectory (proccontrol)
91 add_subdirectory (stackwalk)
92 add_subdirectory (dyninstAPI)
93 add_subdirectory (dyninstAPI_RT)
94
95 if(UNIX)
96 add_dependencies(dynDwarf libdwarf_imp)
97 add_dependencies(dynElf libelf_imp)
98 add_dependencies(common libiberty_imp)
99 add_dependencies(libdwarf_imp libelf_imp)
100 endif()
101
102 if(CMAKE_COMPILER_IS_GNUCXX)
103     set (CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden)
104     set (CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden)
105     message(STATUS "Found g++, enabling -fvisibility=hidden")
106 endif()
107
108 if(NOT ${PLATFORM} MATCHES nt)
109     SET_TARGET_PROPERTIES (
110         common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
111         patchAPI pcontrol stackwalk dyninstAPI
112         PROPERTIES
113             SOVERSION ${SOVERSION}
114             VERSION ${LIBVERSION}
115     )
116 else()
117     SET_TARGET_PROPERTIES (
118         common instructionAPI symtabAPI parseAPI
119         patchAPI pcontrol stackwalk dyninstAPI
120         PROPERTIES
121             SOVERSION ${SOVERSION}
122             VERSION ${LIBVERSION}
123     )
124
125 endif()
126
127 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
128     add_definitions(-Dsnprintf=_snprintf)
129 endif()
130
131 # RTlib properties are set in its CMakeLists.txt; it seems
132 # like multiple set_target_properties calls override instead
133 # of accumulating
134
135
136
137
138
139 #
140 # DyninstConfig.cmake
141
142 # Not sure if needed...
143 #export (PACKAGE Dyninst)
144
145 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
146
147 # For the build tree
148 # I don't think we want this; it doesn't work quite right
149 #foreach (dir ${HEADER_DIRS})
150 #    set (CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/${dir}/h)
151 #endforeach()
152 #configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}/DyninstConfig.cmake" @ONLY)
153
154
155 # For the install tree
156 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
157
158 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
159
160 # And version file
161 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)
162 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/DyninstConfigVersion.cmake" @ONLY)
163
164 if(UNIX)
165 get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
166 file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
167 message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
168 message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
169 message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
170 install (FILES ${LIBDWARF_LIBRARIES} ${LIBELF_INSTALL_FILES}
171         DESTINATION "${INSTALL_LIB_DIR}")
172 endif()
173 install (FILES
174         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
175         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
176         DESTINATION "${INSTALL_CMAKE_DIR}")
177 install (EXPORT DyninstTargets
178         DESTINATION "${INSTALL_CMAKE_DIR}")