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