CMake changes for better/safer RTlib assembly building.
[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 CACHE STRING "Compiler for runtime library")
82 else()
83   set (RT_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "Compiler for runtime library")
84 endif()
85 set (NEED_NATIVE_ASSEMBLER NO CACHE STRING "Does the compiler break on assembly files? (Unlikely)")
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   -DBUILD_RTLIB_32=${BUILD_RTLIB_32}
98   -DNEED_NATIVE_ASSEMBLER=${NEED_NATIVE_ASSEMBLER}
99   -DPLATFORM=${PLATFORM}
100   -G ${CMAKE_GENERATOR}
101   ${RT_SOURCE_DIR})
102
103 add_custom_target(DyninstRT
104   ALL
105   #  COMMAND ${CMAKE_COMMAND} -E chdir ${RT_BINARY_DIR} ${ACTUAL_BUILD}
106   ${CMAKE_BUILD_TOOL}
107   WORKING_DIRECTORY ${RT_BINARY_DIR}
108   COMMENT "Building DyninstRT")
109
110
111
112 if(UNIX)
113   message(STATUS "Adding Unix-specific dependencies")
114   add_dependencies(dynDwarf libdwarf_imp)
115   add_dependencies(dynElf libelf_imp)
116   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
117   if (NOT USE_GNU_DEMANGLER)
118     add_dependencies(common libiberty_imp)
119   endif()
120   if(NOT LIBDWARF_FOUND)
121     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
122     add_dependencies(libdwarf_imp libelf_imp)
123   endif()
124 endif()
125
126 if(NOT ${PLATFORM} MATCHES nt)
127   SET_TARGET_PROPERTIES (
128     common dynElf dynDwarf instructionAPI symtabAPI symLite parseAPI
129     patchAPI pcontrol stackwalk dyninstAPI dynC_API
130     PROPERTIES
131     SOVERSION ${SOVERSION}
132     VERSION ${LIBVERSION}
133     CLEAN_DIRECT_OUTPUT 1
134     )
135 else()
136   SET_TARGET_PROPERTIES (
137     common instructionAPI symtabAPI parseAPI
138     patchAPI pcontrol stackwalk dyninstAPI
139     PROPERTIES
140     SOVERSION ${SOVERSION}
141     VERSION ${LIBVERSION}
142     CLEAN_DIRECT_OUTPUT 1
143
144     )
145
146 endif()
147
148 if(UNIX)
149   if(SHOULD_INSTALL_LIBELF)
150     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
151     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
152     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
153     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
154     install (FILES ${LIBELF_INSTALL_FILES}
155       DESTINATION "${INSTALL_LIB_DIR}")
156   endif()
157   if(NOT LIBDWARF_FOUND)
158     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
159     install (FILES ${LIBDWARF_LIBRARIES}
160       DESTINATION "${INSTALL_LIB_DIR}")
161   endif()
162 endif()
163 install (FILES
164   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake"
165   "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake"
166   DESTINATION "${INSTALL_CMAKE_DIR}")
167 install (EXPORT DyninstTargets
168   DESTINATION "${INSTALL_CMAKE_DIR}")
169 #install(CODE "include(\"${RT_BINARY_DIR}/cmake_install.cmake\")")
170 install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
171
172 configure_file(cmake/DyninstConfig.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfig.cmake" @ONLY)
173
174 # And version file
175 configure_file(cmake/DyninstConfigVersion.cmake.in "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/DyninstConfigVersion.cmake" @ONLY)