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