Initial dynC CMakeLists
[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 add_subdirectory (dynC_API)
69
70 #Build the RT library as a seperate project so we can change compilers
71 message(STATUS "Configuring DyninstAPI_RT")
72 set(RT_SOURCE_DIR ${DYNINST_ROOT}/dyninstAPI_RT)
73 set(RT_BINARY_DIR ${PROJECT_BINARY_DIR}/dyninstAPI_RT)
74 file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile ${RT_BINARY_DIR}/Makefile)
75 file(MAKE_DIRECTORY ${RT_BINARY_DIR})
76 if (PLATFORM MATCHES bgq)
77   set (RT_C_COMPILER mpicc)
78 else()
79   set (RT_C_COMPILER ${CMAKE_C_COMPILER})
80 endif()
81
82 message(STATUS "Configuring RT library")
83
84 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
85   COMMAND ${CMAKE_COMMAND}
86   -DCMAKE_C_COMPILER=${RT_C_COMPILER}
87   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
88   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
89   -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
90   -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
91   -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
92   -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
93   -DPLATFORM=${PLATFORM}
94   -G ${CMAKE_GENERATOR}
95   ${RT_SOURCE_DIR})
96
97 add_custom_target(DyninstRT
98   ALL
99   #  COMMAND ${CMAKE_COMMAND} -E chdir ${RT_BINARY_DIR} ${ACTUAL_BUILD}
100   ${CMAKE_BUILD_TOOL}
101   WORKING_DIRECTORY ${RT_BINARY_DIR}
102   COMMENT "Building DyninstRT")
103
104
105
106 if(UNIX)
107   message(STATUS "Adding Unix-specific dependencies")
108   add_dependencies(dynDwarf libdwarf_imp)
109   add_dependencies(dynElf libelf_imp)
110   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
111   if (NOT USE_GNU_DEMANGLER)
112     add_dependencies(common libiberty_imp)
113   endif()
114   if(NOT LIBDWARF_FOUND)
115     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
116     add_dependencies(libdwarf_imp libelf_imp)
117   endif()
118 endif()
119
120 if(NOT ${PLATFORM} MATCHES nt)
121   SET_TARGET_PROPERTIES (
122     common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
123     patchAPI pcontrol stackwalk dyninstAPI
124     PROPERTIES
125     SOVERSION ${SOVERSION}
126     VERSION ${LIBVERSION}
127     CLEAN_DIRECT_OUTPUT 1
128     )
129 else()
130   SET_TARGET_PROPERTIES (
131     common instructionAPI symtabAPI parseAPI
132     patchAPI pcontrol stackwalk dyninstAPI
133     PROPERTIES
134     SOVERSION ${SOVERSION}
135     VERSION ${LIBVERSION}
136     CLEAN_DIRECT_OUTPUT 1
137
138     )
139
140 endif()
141
142 if(UNIX)
143   if(SHOULD_INSTALL_LIBELF)
144     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
145     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
146     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
147     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
148     install (FILES ${LIBELF_INSTALL_FILES}
149       DESTINATION "${INSTALL_LIB_DIR}")
150   endif()
151   if(NOT LIBDWARF_FOUND)
152     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
153     install (FILES ${LIBDWARF_LIBRARIES}
154       DESTINATION "${INSTALL_LIB_DIR}")
155   endif()
156 endif()
157 install (FILES
158   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
159   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
160   DESTINATION "${INSTALL_CMAKE_DIR}")
161 install (EXPORT DyninstTargets
162   DESTINATION "${INSTALL_CMAKE_DIR}")
163 #install(CODE "include(\"${RT_BINARY_DIR}/cmake_install.cmake\")")
164 install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
165
166 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
167
168 # And version file
169 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)