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