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