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