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