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