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