Merge branch 'master' of git.dyninst.org:/pub/dyninst
[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 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
74   COMMAND ${CMAKE_COMMAND}
75   -DCMAKE_C_COMPILER=${RT_C_COMPILER}
76   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
77   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
78   -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
79   -DPLATFORM=${PLATFORM}
80   ${RT_SOURCE_DIR})
81
82 add_custom_target(DyninstRT
83   ALL
84   COMMAND ${CMAKE_COMMAND} --build ${RT_BINARY_DIR}
85   COMMENT "Building DyninstRT"
86   VERBATIM)
87 install(CODE "include(\"${RT_BINARY_DIR}/cmake_install.cmake\")")
88
89
90 if(UNIX)
91   message(STATUS "Adding Unix-specific dependencies")
92   add_dependencies(dynDwarf libdwarf_imp)
93   add_dependencies(dynElf libelf_imp)
94   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
95   if (NOT USE_GNU_DEMANGLER)
96     add_dependencies(common libiberty_imp)
97   endif()
98   if(NOT LIBDWARF_FOUND)
99     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
100     add_dependencies(libdwarf_imp libelf_imp)
101   endif()
102 endif()
103
104 if(NOT ${PLATFORM} MATCHES nt)
105   SET_TARGET_PROPERTIES (
106     common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
107     patchAPI pcontrol stackwalk dyninstAPI
108     PROPERTIES
109     SOVERSION ${SOVERSION}
110     VERSION ${LIBVERSION}
111     )
112 else()
113   SET_TARGET_PROPERTIES (
114     common instructionAPI symtabAPI parseAPI
115     patchAPI pcontrol stackwalk dyninstAPI
116     PROPERTIES
117     SOVERSION ${SOVERSION}
118     VERSION ${LIBVERSION}
119     )
120
121 endif()
122
123 if(UNIX)
124   if(SHOULD_INSTALL_LIBELF)
125     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
126     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
127     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
128     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
129     install (FILES ${LIBELF_INSTALL_FILES}
130       DESTINATION "${INSTALL_LIB_DIR}")
131   endif()
132   if(NOT LIBDWARF_FOUND)
133     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
134     install (FILES ${LIBDWARF_LIBRARIES}
135       DESTINATION "${INSTALL_LIB_DIR}")
136   endif()
137 endif()
138 install (FILES
139   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
140   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
141   DESTINATION "${INSTALL_CMAKE_DIR}")
142 install (EXPORT DyninstTargets
143   DESTINATION "${INSTALL_CMAKE_DIR}")
144
145 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
146
147 # And version file
148 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)