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