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