Merge remote-tracking branch 'origin/master' into v8.2
[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 include (${DYNINST_ROOT}/cmake/shared.cmake)
15
16 if(${PLATFORM} MATCHES nt)
17   set (HEADER_DIRS common
18     dataflowAPI
19     dyninstAPI
20     dynutil
21     instructionAPI
22     parseAPI
23     patchAPI
24     proccontrol
25     stackwalk
26     symtabAPI
27     )
28 else()
29   set (HEADER_DIRS common
30     dataflowAPI
31     dwarf
32     dyninstAPI
33     dynutil
34     elf
35     instructionAPI
36     parseAPI
37     patchAPI
38     proccontrol
39     stackwalk
40     symlite
41     symtabAPI
42     )
43 endif()
44
45 foreach (dir ${HEADER_DIRS})
46   include_directories ( ${DYNINST_ROOT}/${dir}/h )
47 endforeach()
48
49 include_directories (
50   ${DYNINST_ROOT}
51   ${DYNINST_ROOT}/external
52   )
53
54 # Component time
55 add_subdirectory (common)
56 if(NOT ${PLATFORM} MATCHES nt)
57   add_subdirectory (elf)
58   add_subdirectory (dwarf)
59   add_subdirectory (symlite)
60 endif()
61 add_subdirectory (instructionAPI)
62 add_subdirectory (symtabAPI)
63 add_subdirectory (parseAPI)
64 add_subdirectory (patchAPI)
65 add_subdirectory (proccontrol)
66 add_subdirectory (stackwalk)
67 add_subdirectory (dyninstAPI)
68
69 #Build the RT library as a seperate project so we can change compilers
70 message(STATUS "Configuring DyninstAPI_RT")
71 set(RT_SOURCE_DIR ${DYNINST_ROOT}/dyninstAPI_RT)
72 set(RT_BINARY_DIR ${PROJECT_BINARY_DIR}/dyninstAPI_RT)
73 file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile ${RT_BINARY_DIR}/Makefile)
74 file(MAKE_DIRECTORY ${RT_BINARY_DIR})
75 if (PLATFORM MATCHES bgq)
76   set (RT_C_COMPILER mpicc)
77 else()
78   set (RT_C_COMPILER ${CMAKE_C_COMPILER})
79 endif()
80
81 message(STATUS "Configuring RT library")
82
83 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
84   COMMAND ${CMAKE_COMMAND}
85   -DCMAKE_C_COMPILER=${RT_C_COMPILER}
86   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
87   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
88   -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
89   -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
90   -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
91   -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
92   -DPLATFORM=${PLATFORM}
93   -G ${CMAKE_GENERATOR}
94   ${RT_SOURCE_DIR})
95
96 add_custom_target(DyninstRT
97   ALL
98   #  COMMAND ${CMAKE_COMMAND} -E chdir ${RT_BINARY_DIR} ${ACTUAL_BUILD}
99   ${CMAKE_BUILD_TOOL}
100   WORKING_DIRECTORY ${RT_BINARY_DIR}
101   COMMENT "Building DyninstRT")
102
103
104
105 if(UNIX)
106   message(STATUS "Adding Unix-specific dependencies")
107   add_dependencies(dynDwarf libdwarf_imp)
108   add_dependencies(dynElf libelf_imp)
109   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
110   if (NOT USE_GNU_DEMANGLER)
111     add_dependencies(common libiberty_imp)
112   endif()
113   if(NOT LIBDWARF_FOUND)
114     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
115     add_dependencies(libdwarf_imp libelf_imp)
116   endif()
117 endif()
118
119 if(NOT ${PLATFORM} MATCHES nt)
120   SET_TARGET_PROPERTIES (
121     common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
122     patchAPI pcontrol stackwalk dyninstAPI
123     PROPERTIES
124     SOVERSION ${SOVERSION}
125     VERSION ${LIBVERSION}
126     CLEAN_DIRECT_OUTPUT 1
127     )
128 else()
129   SET_TARGET_PROPERTIES (
130     common instructionAPI symtabAPI parseAPI
131     patchAPI pcontrol stackwalk dyninstAPI
132     PROPERTIES
133     SOVERSION ${SOVERSION}
134     VERSION ${LIBVERSION}
135     CLEAN_DIRECT_OUTPUT 1
136
137     )
138
139 endif()
140
141 if(UNIX)
142   if(SHOULD_INSTALL_LIBELF)
143     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
144     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
145     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
146     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
147     install (FILES ${LIBELF_INSTALL_FILES}
148       DESTINATION "${INSTALL_LIB_DIR}")
149   endif()
150   if(NOT LIBDWARF_FOUND)
151     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
152     install (FILES ${LIBDWARF_LIBRARIES}
153       DESTINATION "${INSTALL_LIB_DIR}")
154   endif()
155 endif()
156 install (FILES
157   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
158   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
159   DESTINATION "${INSTALL_CMAKE_DIR}")
160 install (EXPORT DyninstTargets
161   DESTINATION "${INSTALL_CMAKE_DIR}")
162 #install(CODE "include(\"${RT_BINARY_DIR}/cmake_install.cmake\")")
163 install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
164
165 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
166
167 # And version file
168 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)