Two-pass LATEX for generating correct references
[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 if(${PLATFORM} MATCHES nt)
20   set (HEADER_DIRS common
21     dataflowAPI
22     dyninstAPI
23     dynutil
24     instructionAPI
25     parseAPI
26     patchAPI
27     proccontrol
28     stackwalk
29     symtabAPI
30     )
31 else()
32   set (HEADER_DIRS common
33     dataflowAPI
34     dwarf
35     dyninstAPI
36     dynutil
37     elf
38     instructionAPI
39     parseAPI
40     patchAPI
41     proccontrol
42     stackwalk
43     symlite
44     symtabAPI
45     )
46 endif()
47
48 foreach (dir ${HEADER_DIRS})
49   include_directories ( ${DYNINST_ROOT}/${dir}/h )
50 endforeach()
51
52 include_directories (
53   ${DYNINST_ROOT}
54   ${DYNINST_ROOT}/external
55   )
56 set(Boost_USE_STATIC_LIBS OFF)
57 # Component time
58 add_subdirectory (common)
59 if(NOT ${PLATFORM} MATCHES nt)
60   add_subdirectory (elf)
61   add_subdirectory (dwarf)
62 if(SYMREADER MATCHES symLite)
63   add_subdirectory (symlite)
64 endif()
65 # DynC is not compatible with Windows when
66 # we use bison on linux to generate source
67 # TODO: generate with bison configured for
68 # MSVC?
69   add_subdirectory (dynC_API)
70 endif()
71 add_subdirectory (instructionAPI)
72 add_subdirectory (symtabAPI)
73 add_subdirectory (parseAPI)
74 add_subdirectory (patchAPI)
75 add_subdirectory (proccontrol)
76 add_subdirectory (stackwalk)
77 add_subdirectory (dyninstAPI)
78
79 #Build the RT library as a seperate project so we can change compilers
80 message(STATUS "Configuring DyninstAPI_RT")
81 file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile ${RT_BINARY_DIR}/Makefile)
82 file(MAKE_DIRECTORY ${RT_BINARY_DIR})
83 if (PLATFORM MATCHES bgq)
84   set (RT_C_COMPILER mpicc CACHE STRING "Compiler for runtime library")
85 else()
86   set (RT_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "Compiler for runtime library")
87 endif()
88 set (NEED_NATIVE_ASSEMBLER NO CACHE STRING "Does the compiler break on assembly files? (Unlikely)")
89 set (ENABLE_STATIC_LIBS NO CACHE STRING "Build static libraries as well?")
90 message(STATUS "Configuring RT library")
91
92 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
93   COMMAND ${CMAKE_COMMAND}
94   -DCMAKE_C_COMPILER=${RT_C_COMPILER}
95   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
96   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
97   -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
98   -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
99   -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
100   -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
101   -DBUILD_RTLIB_32=${BUILD_RTLIB_32}
102   -DNEED_NATIVE_ASSEMBLER=${NEED_NATIVE_ASSEMBLER}
103   -DPLATFORM=${PLATFORM}
104   -G ${CMAKE_GENERATOR}
105   ${RT_SOURCE_DIR})
106
107 add_custom_target(DyninstRT
108   ALL
109   #  COMMAND ${CMAKE_COMMAND} -E chdir ${RT_BINARY_DIR} ${ACTUAL_BUILD}
110   ${CMAKE_BUILD_TOOL}
111   WORKING_DIRECTORY ${RT_BINARY_DIR}
112   COMMENT "Building DyninstRT")
113
114 install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
115
116 set (VERSION_STRING "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}.${DYNINST_PATCH_VERSION}")
117 set (DYNINST_NAME "DyninstAPI-${VERSION_STRING}")
118
119 find_package(Git)
120 if(GIT_FOUND)
121 add_custom_target(package ALL)
122 add_custom_command(TARGET package
123   COMMAND ${GIT_EXECUTABLE} archive --prefix="${DYNINST_NAME}/" -o "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz" HEAD
124   WORKING_DIRECTORY ${DYNINST_ROOT}
125   COMMENT "Packaging Dyninst")
126 install(FILES "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz"
127   DESTINATION ${CMAKE_INSTALL_PREFIX})
128 endif()
129
130 add_custom_target(doc)
131 set(LATEX_DOCS dynC_API instructionAPI parseAPI patchAPI symtabAPI stackwalk)
132 set(WORD_DOCS proccontrol dyninstAPI)
133 add_custom_target(proccontrol-doc
134   DEPENDS ${CMAKE_SOURCE_DIR}/proccontrol/doc/proccontrol.pdf)
135 add_custom_target(dyninstAPI-doc
136   DEPENDS ${CMAKE_SOURCE_DIR}/dyninstAPI/doc/dyninstAPI.pdf)
137 add_dependencies(dyninstAPI dyninstAPI-doc)
138 add_dependencies(pcontrol proccontrol-doc)
139 foreach(COMPONENT ${WORD_DOCS})
140   add_dependencies(doc ${COMPONENT}-doc)
141   install(FILES ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
142     DESTINATION ${INSTALL_DOC_DIR}
143     RENAME ${COMPONENT}-${VERSION_STRING}.pdf
144     )
145 endforeach()
146
147 find_package(LATEX)
148 if(PDFLATEX_COMPILER)
149   file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/common/doc
150     DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/common)
151   foreach(COMPONENT ${LATEX_DOCS})
152     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc
153       DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT})
154     add_custom_command(
155 #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
156       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
157       DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.tex
158       COMMAND ${PDFLATEX_COMPILER}
159       ARGS -interaction=batchmode ${COMPONENT}.tex
160       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
161       COMMENT "Latex (first pass)"
162       )
163     add_custom_command(
164       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
165       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
166 #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
167 #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
168       COMMAND ${PDFLATEX_COMPILER}
169       ARGS -interaction=batchmode ${COMPONENT}.tex
170       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
171       COMMENT "Latex (second pass)"
172       )
173     add_custom_target(${COMPONENT}-doc ALL echo
174 #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
175       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
176       )
177     add_dependencies(doc ${COMPONENT}-doc)
178     add_dependencies(${COMPONENT} ${COMPONENT}-doc)
179     install(FILES  ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
180       DESTINATION ${INSTALL_DOC_DIR}
181       RENAME ${COMPONENT}-${VERSION_STRING}.pdf
182       )
183       
184       
185   endforeach()
186 else()
187   message(STATUS "LaTeX not found")
188 endif()
189
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