Move docs back to main repository, with CMake targets for ${COMPONENT}-doc, automatic...
[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   foreach(COMPONENT ${LATEX_DOCS})
150     add_custom_target(${COMPONENT}-doc
151       DEPENDS ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.tex
152       )
153     add_custom_command(TARGET ${COMPONENT}-doc
154       COMMAND ${PDFLATEX_COMPILER} ${COMPONENT}.tex
155       WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc
156       COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf ${CMAKE_BINARY_DIR}/${COMPONENT}.pdf
157       COMMENT "Building ${COMPONENT} manual"
158       )
159
160     add_dependencies(doc ${COMPONENT}-doc)
161     add_dependencies(${COMPONENT} ${COMPONENT}-doc)
162     install(FILES  ${CMAKE_BINARY_DIR}/${COMPONENT}.pdf
163       DESTINATION ${INSTALL_DOC_DIR}
164       RENAME ${COMPONENT}-${VERSION_STRING}.pdf
165       )
166       
167       
168   endforeach()
169 else()
170   message(STATUS "LaTeX not found")
171 endif()
172
173
174 if(UNIX)
175   message(STATUS "Adding Unix-specific dependencies")
176   add_dependencies(dynDwarf libdwarf_imp)
177   add_dependencies(dynElf libelf_imp)
178   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
179   if (NOT USE_GNU_DEMANGLER)
180     add_dependencies(common libiberty_imp)
181   endif()
182   if(NOT LIBDWARF_FOUND)
183     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
184     add_dependencies(libdwarf_imp libelf_imp)
185   endif()
186   if(SHOULD_INSTALL_LIBELF)
187     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
188     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
189     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
190     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
191     install (FILES ${LIBELF_INSTALL_FILES}
192       DESTINATION "${INSTALL_LIB_DIR}")
193   endif()
194   if(NOT LIBDWARF_FOUND)
195     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
196     install (FILES ${LIBDWARF_LIBRARIES}
197       DESTINATION "${INSTALL_LIB_DIR}")
198   endif()
199 endif()
200