CMake integration for Windows.
[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(NOT ${PLATFORM} MATCHES nt)
92     SET_TARGET_PROPERTIES (
93         common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
94         patchAPI pcontrol stackwalk dyninstAPI dyninstAPI_RT
95         PROPERTIES
96             SOVERSION ${SOVERSION}
97             VERSION ${LIBVERSION}
98     )
99 else()
100     SET_TARGET_PROPERTIES (
101         common instructionAPI symtabAPI parseAPI
102         patchAPI pcontrol stackwalk dyninstAPI dyninstAPI_RT
103         PROPERTIES
104             SOVERSION ${SOVERSION}
105             VERSION ${LIBVERSION}
106     )
107
108 endif()
109
110 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
111     add_definitions(-Dsnprintf=_snprintf)
112 endif()
113
114 # RTlib properties are set in its CMakeLists.txt; it seems
115 # like multiple set_target_properties calls override instead
116 # of accumulating
117
118
119
120
121
122 #
123 # DyninstConfig.cmake
124
125 # Not sure if needed...
126 #export (PACKAGE Dyninst)
127
128 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
129
130 # For the build tree
131 # I don't think we want this; it doesn't work quite right
132 #foreach (dir ${HEADER_DIRS})
133 #    set (CONF_INCLUDE_DIRS ${CONF_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/${dir}/h)
134 #endforeach()
135 #configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}/DyninstConfig.cmake" @ONLY)
136
137
138 # For the install tree
139 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_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)
145 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}/DyninstConfigVersion.cmake" @ONLY)
146
147 install (FILES
148         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
149         "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
150         DESTINATION "${INSTALL_CMAKE_DIR}")
151 install (EXPORT DyninstTargets
152         DESTINATION "${INSTALL_CMAKE_DIR}")