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