Merge branch 'release9.2/fixes/make-install-fix' into release9.2/fixes/jenkins-fix
[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   add_subdirectory (parseThat)
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 if(${SYMREADER} MATCHES symtabAPI)
72   add_subdirectory (dynC_API)
73 endif()
74 endif()
75 add_subdirectory (instructionAPI)
76 add_subdirectory (symtabAPI)
77 add_subdirectory (parseAPI)
78 add_subdirectory (proccontrol)
79 add_subdirectory (stackwalk)
80 add_subdirectory (patchAPI)
81 if(${SYMREADER} MATCHES symtabAPI)
82   add_subdirectory (dyninstAPI)
83 endif()
84
85 if(BUILD_RTLIB)
86   # Build the RT library as a separate project so we can change compilers
87   message(STATUS "Configuring DyninstAPI_RT")
88   file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile)
89   file(MAKE_DIRECTORY ${RT_BINARY_DIR})
90   if (PLATFORM MATCHES bgq)
91     set (RT_C_COMPILER mpicc CACHE STRING "Compiler for runtime library")
92   else()
93     set (RT_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "Compiler for runtime library")
94   endif()
95   set (ENABLE_STATIC_LIBS NO CACHE STRING "Build static libraries as well?")
96   message(STATUS "Configuring RT library")
97
98   execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
99     COMMAND ${CMAKE_COMMAND}
100     -DCMAKE_C_COMPILER=${RT_C_COMPILER}
101     -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
102     -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
103     -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
104     -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
105     -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
106     -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
107     -DBUILD_RTLIB_32=${BUILD_RTLIB_32}
108     -DPLATFORM=${PLATFORM}
109     -G ${CMAKE_GENERATOR}
110     ${RT_SOURCE_DIR})
111
112   if(MSVC)
113       include_external_msproject(DyninstAPI_RT dyninstAPI_RT/dyninstAPI_RT.vcxproj)
114           include_external_msproject(DyninstAPI_RT_static dyninstAPI_RT/dyninstAPI_RT_static.vcxproj)
115   else()
116     add_custom_target(DyninstRT
117       ALL
118       $(MAKE)
119       WORKING_DIRECTORY ${RT_BINARY_DIR}
120       COMMENT "Building DyninstRT")
121     add_dependencies(dyninstAPI DyninstRT)
122     if(TARGET dyninstAPI-static)
123       add_dependencies(dyninstAPI-static DyninstRT)
124     endif()
125   endif()
126
127   install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
128
129 else()
130   message(STATUS "Skipping DyninstAPI_RT. Be sure to build this library if you're using instrumentation.")
131 endif()
132 set (VERSION_STRING "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}.${DYNINST_PATCH_VERSION}")
133 set (DYNINST_NAME "DyninstAPI-${VERSION_STRING}")
134
135 if(BUILD_TARBALLS)
136   find_package(Git)
137   if(GIT_FOUND)
138     if(EXISTS "${DYNINST_ROOT}/.git/")
139       message(STATUS "Source tree is repository, building archive target")
140       add_custom_target(package ALL)
141       add_custom_command(TARGET package
142         COMMAND ${GIT_EXECUTABLE} archive --prefix="${DYNINST_NAME}/" --format=tar.gz -o "${CMAKE_BINARY_DIR}/${DYNINST_NAME}.tgz" HEAD
143         WORKING_DIRECTORY ${DYNINST_ROOT}
144         COMMENT "Packaging Dyninst")
145     endif()
146   endif()
147 endif()
148 if(BUILD_DOCS)
149   add_custom_target(doc)
150   set(LATEX_DOCS dynC_API dataflowAPI instructionAPI parseAPI patchAPI symtabAPI stackwalk)
151   set(WORD_DOCS proccontrol dyninstAPI)
152   add_custom_target(proccontrol-doc
153     DEPENDS ${CMAKE_SOURCE_DIR}/proccontrol/doc/proccontrol.pdf)
154   add_custom_target(dyninstAPI-doc
155     DEPENDS ${CMAKE_SOURCE_DIR}/dyninstAPI/doc/dyninstAPI.pdf)
156   foreach(COMPONENT ${WORD_DOCS})
157     add_dependencies(doc ${COMPONENT}-doc)
158     set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
159     install(FILES ${CMAKE_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
160       DESTINATION ${INSTALL_DOC_DIR}
161       RENAME ${COMPONENT}-${VERSION_STRING}.pdf
162       OPTIONAL
163       )
164   endforeach()
165
166   #set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
167   find_package(LATEX)
168   if(PDFLATEX_COMPILER)
169     file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/common/doc
170       DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/common)
171     foreach(COMPONENT ${LATEX_DOCS})
172       file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc
173         DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT})
174       set (DEPS "")
175       file(GLOB_RECURSE DEPS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/*.tex ${CMAKE_CURRENT_SOURCE_DIR}/common/doc/*.tex)
176       #message(STATUS "Found dependencies for ${COMPONENT} manual: ${DEPS}")
177       add_custom_command(
178         #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
179         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
180         DEPENDS ${DEPS} #${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.tex
181         COMMAND ${PDFLATEX_COMPILER}
182         ARGS -interaction=batchmode ${COMPONENT}.tex
183         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
184         COMMENT "Latex (first pass)"
185         )
186       add_custom_command(
187         OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
188         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
189         #      OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
190         #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.aux
191         COMMAND ${PDFLATEX_COMPILER}
192         ARGS -interaction=batchmode ${COMPONENT}.tex
193         WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc
194         COMMENT "Latex (second pass)"
195         )
196       add_custom_target(${COMPONENT}-doc echo
197         #      DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/doc/${COMPONENT}.log
198         DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.log
199         )
200       add_dependencies(doc ${COMPONENT}-doc)
201       set_target_properties(${COMPONENT}-doc PROPERTIES EXCLUDE_FROM_DEFAULT_BUILD 1)
202       #add_dependencies(${COMPONENT} ${COMPONENT}-doc)
203       install(FILES  ${CMAKE_CURRENT_BINARY_DIR}/${COMPONENT}/doc/${COMPONENT}.pdf
204         DESTINATION ${INSTALL_DOC_DIR}
205         RENAME ${COMPONENT}-${VERSION_STRING}.pdf
206         OPTIONAL
207         )
208     endforeach()
209   else()
210     message(STATUS "LaTeX not found")
211   endif()
212 endif()
213
214 if(UNIX)
215   message(STATUS "Adding Unix-specific dependencies")
216   add_dependencies(dynDwarf libdwarf_imp)
217   add_dependencies(dynElf libelf_imp)
218   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
219   if (NOT USE_GNU_DEMANGLER)
220     add_dependencies(common libiberty_imp)
221   endif()
222   if(NOT LIBDWARF_FOUND)
223     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
224     add_dependencies(libdwarf_imp libelf_imp)
225   endif()
226   if(SHOULD_INSTALL_LIBELF)
227     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
228     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
229     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
230     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
231     install (FILES ${LIBELF_INSTALL_FILES}
232       DESTINATION "${INSTALL_LIB_DIR}")
233   endif()
234   if(NOT LIBDWARF_FOUND)
235     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
236     install (FILES ${LIBDWARF_LIBRARIES}
237       DESTINATION "${INSTALL_LIB_DIR}")
238   endif()
239 endif()
240