Only build the package target if the source tree is a git checkout.
[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 if(EXISTS "${DYNINST_ROOT}/.git/")
122 message(STATUS "Source tree is repository, building archive target")
123 add_custom_target(package ALL)
124 add_custom_command(TARGET package
125   COMMAND ${GIT_EXECUTABLE} archive --prefix="${DYNINST_NAME}/" -o "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz" HEAD
126   WORKING_DIRECTORY ${DYNINST_ROOT}
127   COMMENT "Packaging Dyninst")
128 install(FILES "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz"
129   DESTINATION ${CMAKE_INSTALL_PREFIX})
130 endif()
131 endif()
132
133 add_custom_target(doc)
134 set(LATEX_DOCS dynC_API 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   install(FILES ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
143     DESTINATION ${INSTALL_DOC_DIR}
144     RENAME ${COMPONENT}-${VERSION_STRING}.pdf
145     OPTIONAL
146     )
147 endforeach()
148
149 #set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
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     #message(STATUS "Found dependencies for ${COMPONENT} manual: ${DEPS}")
160     add_custom_command(
161       #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
162       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
163       DEPENDS ${DEPS} #${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.tex
164       COMMAND ${PDFLATEX_COMPILER}
165       ARGS -interaction=batchmode ${COMPONENT}.tex
166       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
167       COMMENT "Latex (first pass)"
168       )
169     add_custom_command(
170       OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
171       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
172       #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
173       #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
174       COMMAND ${PDFLATEX_COMPILER}
175       ARGS -interaction=batchmode ${COMPONENT}.tex
176       WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
177       COMMENT "Latex (second pass)"
178       )
179     add_custom_target(${COMPONENT}-doc echo
180       #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
181       DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
182       )
183     add_dependencies(doc ${COMPONENT}-doc)
184     #add_dependencies(${COMPONENT} ${COMPONENT}-doc)
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
195 if(UNIX)
196   message(STATUS "Adding Unix-specific dependencies")
197   add_dependencies(dynDwarf libdwarf_imp)
198   add_dependencies(dynElf libelf_imp)
199   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
200   if (NOT USE_GNU_DEMANGLER)
201     add_dependencies(common libiberty_imp)
202   endif()
203   if(NOT LIBDWARF_FOUND)
204     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
205     add_dependencies(libdwarf_imp libelf_imp)
206   endif()
207   if(SHOULD_INSTALL_LIBELF)
208     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
209     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
210     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
211     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
212     install (FILES ${LIBELF_INSTALL_FILES}
213       DESTINATION "${INSTALL_LIB_DIR}")
214   endif()
215   if(NOT LIBDWARF_FOUND)
216     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
217     install (FILES ${LIBDWARF_LIBRARIES}
218       DESTINATION "${INSTALL_LIB_DIR}")
219   endif()
220 endif()
221