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