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