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