Explicitly link Symtab against Boost libs
[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 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 # DynC is not compatible with Windows when
57 # we use bison on linux to generate source
58 # TODO: generate with bison configured for
59 # MSVC?
60 if(${SYMREADER} MATCHES symtabAPI)
61   add_subdirectory (dynC_API)
62 endif()
63 endif()
64 add_subdirectory (instructionAPI)
65 add_subdirectory (symtabAPI)
66 add_subdirectory (parseAPI)
67 add_subdirectory (proccontrol)
68 add_subdirectory (stackwalk)
69 add_subdirectory (patchAPI)
70 if(${SYMREADER} MATCHES symtabAPI)
71   add_subdirectory (dyninstAPI)
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")
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
101   if(MSVC)
102       include_external_msproject(DyninstAPI_RT dyninstAPI_RT/dyninstAPI_RT.vcxproj)
103           include_external_msproject(DyninstAPI_RT_static dyninstAPI_RT/dyninstAPI_RT_static.vcxproj)
104   else()
105     add_custom_target(DyninstRT
106       ALL
107       $(MAKE)
108       WORKING_DIRECTORY ${RT_BINARY_DIR}
109       COMMENT "Building DyninstRT")
110     add_dependencies(dyninstAPI DyninstRT)
111     if(TARGET dyninstAPI-static)
112       add_dependencies(dyninstAPI-static DyninstRT)
113     endif()
114   endif()
115
116   install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
117
118 else()
119   message(STATUS "Skipping DyninstAPI_RT. Be sure to build this library if you're using instrumentation.")
120 endif()
121 set (VERSION_STRING "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}.${DYNINST_PATCH_VERSION}")
122 set (DYNINST_NAME "DyninstAPI-${VERSION_STRING}")
123
124 if(BUILD_TARBALLS)
125   find_package(Git)
126   if(GIT_FOUND)
127     if(EXISTS "${DYNINST_ROOT}/.git/")
128       message(STATUS "Source tree is repository, building archive target")
129       add_custom_target(package ALL)
130       add_custom_command(TARGET package
131         COMMAND ${GIT_EXECUTABLE} archive --prefix="${DYNINST_NAME}/" --format=tar.gz -o "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz" HEAD
132         WORKING_DIRECTORY ${DYNINST_ROOT}
133         COMMENT "Packaging Dyninst")
134     endif()
135   endif()
136 endif()
137 if(BUILD_DOCS)
138   add_custom_target(doc)
139   set(LATEX_DOCS dynC_API dataflowAPI instructionAPI parseAPI patchAPI symtabAPI stackwalk)
140   set(WORD_DOCS proccontrol dyninstAPI)
141   add_custom_target(proccontrol-doc
142     DEPENDS ${CMAKE_SOURCE_DIR}/proccontrol/doc/proccontrol.pdf)
143   add_custom_target(dyninstAPI-doc
144     DEPENDS ${CMAKE_SOURCE_DIR}/dyninstAPI/doc/dyninstAPI.pdf)
145   foreach(COMPONENT ${WORD_DOCS})
146     add_dependencies(doc ${COMPONENT}-doc)
147     set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
148     install(FILES ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
149       DESTINATION ${INSTALL_DOC_DIR}
150       RENAME ${COMPONENT}-${VERSION_STRING}.pdf
151       OPTIONAL
152       )
153   endforeach()
154
155   find_package(LATEX)
156   if(PDFLATEX_COMPILER)
157     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/common/doc
158       DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/common)
159     foreach(COMPONENT ${LATEX_DOCS})
160       file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc
161         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT})
162       set (DEPS "")
163       file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/*.tex ${CMAKE_CURRENT_SOURCE_DIR}/common/doc/*.tex)
164       add_custom_command(
165         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
166         DEPENDS ${DEPS}
167         COMMAND ${PDFLATEX_COMPILER}
168         ARGS -interaction=batchmode ${COMPONENT}.tex
169         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
170         COMMENT "Latex (first pass)"
171         )
172       add_custom_command(
173         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
174         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
175         COMMAND ${PDFLATEX_COMPILER}
176         ARGS -interaction=batchmode ${COMPONENT}.tex
177         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
178         COMMENT "Latex (second pass)"
179         )
180       add_custom_target(${COMPONENT}-doc echo
181         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
182         )
183       add_dependencies(doc ${COMPONENT}-doc)
184       set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
185       install(FILES  ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
186         DESTINATION ${INSTALL_DOC_DIR}
187         RENAME ${COMPONENT}-${VERSION_STRING}.pdf
188         OPTIONAL
189         )
190     endforeach()
191   else()
192     message(STATUS "LaTeX not found")
193   endif()
194 endif()
195
196 if(UNIX)
197   message(STATUS "Adding Unix-specific dependencies")
198   add_dependencies(dynDwarf libdwarf_imp)
199   add_dependencies(dynElf libelf_imp)
200   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
201   if (NOT USE_GNU_DEMANGLER)
202     add_dependencies(common libiberty_imp)
203   endif()
204   if(NOT LIBDWARF_FOUND)
205     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
206     add_dependencies(libdwarf_imp libelf_imp)
207   endif()
208   if(SHOULD_INSTALL_LIBELF)
209     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
210     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
211     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
212     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
213     install (FILES ${LIBELF_INSTALL_FILES}
214       DESTINATION "${INSTALL_LIB_DIR}")
215   endif()
216   if(NOT LIBDWARF_FOUND)
217     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
218     install (FILES ${LIBDWARF_LIBRARIES}
219       DESTINATION "${INSTALL_LIB_DIR}")
220   endif()
221 endif()
222
223 if(TARGET boost)
224     add_dependencies(common boost)
225 endif()