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