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