Prevent corruption to rax during stack alignment on x86-64 (#670)
[dyninst.git] / CMakeLists.txt
1 cmake_minimum_required (VERSION 3.4.0)
2 project (Dyninst)
3
4 set (DYNINST_ROOT ${PROJECT_SOURCE_DIR})
5 set (CMAKE_SKIP_BUILD_RPATH FALSE)
6 set (CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
7 set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
8 set (CMAKE_EXPORT_COMPILE_COMMANDS ON)
9
10 set(STERILE_BUILD OFF CACHE BOOL "Do not download/build any third-party dependencies from source")
11
12 LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES 
13           "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
14 IF("${isSystemDir}" STREQUAL "-1")
15                     set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
16 ENDIF()
17
18 set(RT_SOURCE_DIR ${DYNINST_ROOT}/dyninstAPI_RT)
19 set(RT_BINARY_DIR ${PROJECT_BINARY_DIR}/dyninstAPI_RT)
20
21 set (CMAKE_MODULE_PATH "${DYNINST_ROOT}/cmake" "${DYNINST_ROOT}/cmake/Modules" ${CMAKE_MODULE_PATH})
22
23 find_package(ThreadDB)
24 find_package(Threads)
25 include(Boost)
26 include(ThreadingBuildingBlocks)
27 include(ElfUtils)
28 include(LibIberty)
29
30 include(shared)
31
32 # PLATFORM is set by including 'shared'
33 if(PLATFORM MATCHES "bgq")
34   message(WARNING "Support for Bluegene/Q has been deprecated and will be removed in a future release")
35 endif()
36
37 configure_file(cmake/version.h.in common/h/dyninstversion.h)
38 include_directories(${PROJECT_BINARY_DIR})
39 include_directories(${PROJECT_BINARY_DIR}/common/h)
40 set (HEADER_DIRS common
41     dataflowAPI
42     dyninstAPI
43     instructionAPI
44     parseAPI
45     patchAPI
46     proccontrol
47     stackwalk
48     symtabAPI
49     )
50 if(NOT ${PLATFORM} MATCHES nt)
51   set (HEADER_DIRS ${HEADER_DIRS}
52     dwarf
53     elf
54     symlite
55     )
56 endif()
57
58
59
60 foreach (dir ${HEADER_DIRS})
61   include_directories ( ${DYNINST_ROOT}/${dir}/h )
62 endforeach()
63
64
65 include_directories (
66   ${DYNINST_ROOT}
67   ${DYNINST_ROOT}/external
68   ${CILKSCREEN_INCLUDES}
69       ${TBB_INCLUDE_DIRS}
70   )
71
72 # Component time
73 add_subdirectory (common)
74 if(NOT ${PLATFORM} MATCHES nt)
75   add_subdirectory (elf)
76   add_subdirectory (dwarf)
77   add_subdirectory (symlite)
78   add_subdirectory (parseThat)
79 endif()
80 add_subdirectory (instructionAPI)
81 add_subdirectory (symtabAPI)
82 add_subdirectory (parseAPI)
83 add_subdirectory (proccontrol)
84 add_subdirectory (stackwalk)
85 add_subdirectory (patchAPI)
86 add_subdirectory(examples)
87 if(${SYMREADER} MATCHES symtabAPI)
88   add_subdirectory (dyninstAPI)
89   add_subdirectory (dynC_API)
90 endif()
91
92 if(BUILD_RTLIB)
93   # Build the RT library as a separate project so we can change compilers
94   message(STATUS "Configuring DyninstAPI_RT in ${RT_BINARY_DIR}")
95   file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile)
96   file(MAKE_DIRECTORY ${RT_BINARY_DIR})
97   if (PLATFORM MATCHES bgq)
98     set (RT_C_COMPILER mpicc CACHE STRING "Compiler for runtime library")
99   else()
100     set (RT_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "Compiler for runtime library")
101   endif()
102   set (ENABLE_STATIC_LIBS NO CACHE STRING "Build static libraries as well?")
103   message(STATUS "Configuring RT library")
104
105   execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
106     COMMAND ${CMAKE_COMMAND}
107     -DCMAKE_C_COMPILER=${RT_C_COMPILER}
108     -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
109     -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
110     -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
111     -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
112     -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
113     -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
114     -DBUILD_RTLIB_32=${BUILD_RTLIB_32}
115     -DPLATFORM=${PLATFORM}
116     -G ${CMAKE_GENERATOR}
117     ${RT_SOURCE_DIR})
118   find_file(${RT_MAKEFILE} Makefile PATHS ${RT_BINARY_DIR} NO_DEFAULT_PATH)
119   message(STATUS "RTlib Makefile: ${RT_MAKEFILE}")
120   if(MSVC)
121       include_external_msproject(DyninstAPI_RT dyninstAPI_RT/dyninstAPI_RT.vcxproj)
122           include_external_msproject(DyninstAPI_RT_static dyninstAPI_RT/dyninstAPI_RT_static.vcxproj)
123   else()
124     add_custom_target(DyninstRT
125       ALL
126       $(MAKE)
127       WORKING_DIRECTORY ${RT_BINARY_DIR}
128       COMMENT "Building DyninstRT")
129     if(TARGET TBB)
130       add_dependencies(DyninstRT TBB)
131     endif()
132     add_dependencies(dyninstAPI DyninstRT)
133     if(TARGET dyninstAPI-static)
134       add_dependencies(dyninstAPI-static DyninstRT)
135     endif()
136     if(TARGET boost)
137       add_dependencies(DyninstRT boost)
138     endif()
139   endif()
140
141   install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
142
143 else()
144   message(STATUS "Skipping DyninstAPI_RT. Be sure to build this library if you're using instrumentation.")
145 endif()
146 set (VERSION_STRING "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}.${DYNINST_PATCH_VERSION}")
147 set (DYNINST_NAME "DyninstAPI-${VERSION_STRING}")
148
149 if(BUILD_TARBALLS)
150   find_package(Git)
151   if(GIT_FOUND)
152     if(EXISTS "${DYNINST_ROOT}/.git/")
153       message(STATUS "Source tree is repository, building archive target")
154       add_custom_target(package ALL)
155       add_custom_command(TARGET package
156         COMMAND ${GIT_EXECUTABLE} archive --prefix="${DYNINST_NAME}/" --format=tar.gz -o "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz" HEAD
157         WORKING_DIRECTORY ${DYNINST_ROOT}
158         COMMENT "Packaging Dyninst")
159     endif()
160   endif()
161 endif()
162 if(BUILD_DOCS)
163   add_custom_target(doc)
164   set(LATEX_DOCS dynC_API dataflowAPI instructionAPI parseAPI patchAPI symtabAPI stackwalk)
165   set(WORD_DOCS proccontrol dyninstAPI)
166   add_custom_target(proccontrol-doc
167     DEPENDS ${CMAKE_SOURCE_DIR}/proccontrol/doc/proccontrol.pdf)
168   add_custom_target(dyninstAPI-doc
169     DEPENDS ${CMAKE_SOURCE_DIR}/dyninstAPI/doc/dyninstAPI.pdf)
170   foreach(COMPONENT ${WORD_DOCS})
171     add_dependencies(doc ${COMPONENT}-doc)
172     set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
173     install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
174       DESTINATION ${INSTALL_DOC_DIR}
175       RENAME ${COMPONENT}-${VERSION_STRING}.pdf
176       OPTIONAL
177       )
178   endforeach()
179
180   find_package(LATEX)
181   if(PDFLATEX_COMPILER)
182     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/common/doc
183       DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/common)
184     foreach(COMPONENT ${LATEX_DOCS})
185       file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc
186         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT})
187       set (DEPS "")
188       file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/*.tex ${CMAKE_CURRENT_SOURCE_DIR}/common/doc/*.tex)
189       add_custom_command(
190         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
191         DEPENDS ${DEPS}
192         COMMAND ${PDFLATEX_COMPILER}
193         ARGS -interaction=batchmode ${COMPONENT}.tex
194         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
195         COMMENT "Latex (first pass)"
196         )
197       add_custom_command(
198         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
199         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
200         COMMAND ${PDFLATEX_COMPILER}
201         ARGS -interaction=batchmode ${COMPONENT}.tex
202         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
203         COMMENT "Latex (second pass)"
204         )
205       add_custom_target(${COMPONENT}-doc echo
206         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
207         )
208       add_dependencies(doc ${COMPONENT}-doc)
209       set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
210       install(FILES  ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
211         DESTINATION ${INSTALL_DOC_DIR}
212         RENAME ${COMPONENT}-${VERSION_STRING}.pdf
213         OPTIONAL
214         )
215     endforeach()
216   else()
217     message(STATUS "LaTeX not found")
218   endif()
219 endif()
220
221 if(UNIX)
222   message(STATUS "Adding Unix-specific dependencies")
223   if(NOT USE_GNU_DEMANGLER)
224     add_dependencies(common libiberty_imp)
225   endif()
226 endif()
227
228 if(TARGET boost)
229     add_dependencies(common boost)
230 endif()
231
232 #add_subdirectory(testsuite)
233
234 # Copy out all of the cmake files so they can be used by the Testsuite
235 install(DIRECTORY ${DYNINST_ROOT}/cmake/ DESTINATION ${INSTALL_CMAKE_DIR})
236 install(FILES ${PROJECT_BINARY_DIR}/CMakeCache.txt DESTINATION ${INSTALL_CMAKE_DIR})