CMake fixes for building/installing components separately.
[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 set(RT_SOURCE_DIR ${DYNINST_ROOT}/dyninstAPI_RT)
15 set(RT_BINARY_DIR ${PROJECT_BINARY_DIR}/dyninstAPI_RT)
16
17 include (${DYNINST_ROOT}/cmake/shared.cmake)
18
19 if(${PLATFORM} MATCHES nt)
20   set (HEADER_DIRS common
21     dataflowAPI
22     dyninstAPI
23     dynutil
24     instructionAPI
25     parseAPI
26     patchAPI
27     proccontrol
28     stackwalk
29     symtabAPI
30     )
31 else()
32   set (HEADER_DIRS common
33     dataflowAPI
34     dwarf
35     dyninstAPI
36     dynutil
37     elf
38     instructionAPI
39     parseAPI
40     patchAPI
41     proccontrol
42     stackwalk
43     symlite
44     symtabAPI
45     )
46 endif()
47
48 foreach (dir ${HEADER_DIRS})
49   include_directories ( ${DYNINST_ROOT}/${dir}/h )
50 endforeach()
51
52 include_directories (
53   ${DYNINST_ROOT}
54   ${DYNINST_ROOT}/external
55   )
56
57 # Component time
58 add_subdirectory (common)
59 if(NOT ${PLATFORM} MATCHES nt)
60   add_subdirectory (elf)
61   add_subdirectory (dwarf)
62 if(SYMREADER MATCHES symLite)
63   add_subdirectory (symlite)
64 endif()
65 # DynC is not compatible with Windows when
66 # we use bison on linux to generate source
67 # TODO: generate with bison configured for
68 # MSVC?
69   add_subdirectory (dynC_API)
70 endif()
71 add_subdirectory (instructionAPI)
72 add_subdirectory (symtabAPI)
73 add_subdirectory (parseAPI)
74 add_subdirectory (patchAPI)
75 add_subdirectory (proccontrol)
76 add_subdirectory (stackwalk)
77 add_subdirectory (dyninstAPI)
78
79 #Build the RT library as a seperate project so we can change compilers
80 message(STATUS "Configuring DyninstAPI_RT")
81 file(REMOVE_RECURSE ${RT_BINARY_DIR}/CMakeCache.txt ${RT_BINARY_DIR}/CMakeFiles ${RT_BINARY_DIR}/Makefile ${RT_BINARY_DIR}/Makefile)
82 file(MAKE_DIRECTORY ${RT_BINARY_DIR})
83 if (PLATFORM MATCHES bgq)
84   set (RT_C_COMPILER mpicc CACHE STRING "Compiler for runtime library")
85 else()
86   set (RT_C_COMPILER ${CMAKE_C_COMPILER} CACHE STRING "Compiler for runtime library")
87 endif()
88 set (NEED_NATIVE_ASSEMBLER NO CACHE STRING "Does the compiler break on assembly files? (Unlikely)")
89 set (ENABLE_STATIC_LIBS NO CACHE STRING "Build static libraries as well?")
90 message(STATUS "Configuring RT library")
91
92 execute_process(WORKING_DIRECTORY ${RT_BINARY_DIR}
93   COMMAND ${CMAKE_COMMAND}
94   -DCMAKE_C_COMPILER=${RT_C_COMPILER}
95   -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}
96   -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
97   -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH}
98   -DINSTALL_LIB_DIR=${INSTALL_LIB_DIR}
99   -DINSTALL_INCLUDE_DIR=${INSTALL_INCLUDE_DIR}
100   -DCMAKE_C_FLAGS=${CMAKE_C_FLAGS}
101   -DBUILD_RTLIB_32=${BUILD_RTLIB_32}
102   -DNEED_NATIVE_ASSEMBLER=${NEED_NATIVE_ASSEMBLER}
103   -DPLATFORM=${PLATFORM}
104   -G ${CMAKE_GENERATOR}
105   ${RT_SOURCE_DIR})
106
107 add_custom_target(DyninstRT
108   ALL
109   #  COMMAND ${CMAKE_COMMAND} -E chdir ${RT_BINARY_DIR} ${ACTUAL_BUILD}
110   ${CMAKE_BUILD_TOOL}
111   WORKING_DIRECTORY ${RT_BINARY_DIR}
112   COMMENT "Building DyninstRT")
113
114 install(SCRIPT "${RT_BINARY_DIR}/cmake_install.cmake")
115
116 if(UNIX)
117   message(STATUS "Adding Unix-specific dependencies")
118   add_dependencies(dynDwarf libdwarf_imp)
119   add_dependencies(dynElf libelf_imp)
120   message(STATUS "Added libdwarf_imp and libelf_imp dependencies")
121   if (NOT USE_GNU_DEMANGLER)
122     add_dependencies(common libiberty_imp)
123   endif()
124   if(NOT LIBDWARF_FOUND)
125     message(STATUS "Building libdwarf, creating libdwarf dependency on libelf")
126     add_dependencies(libdwarf_imp libelf_imp)
127   endif()
128   if(SHOULD_INSTALL_LIBELF)
129     get_filename_component(ELFDIR "${LIBELF_LIBRARIES}" PATH)
130     file(GLOB LIBELF_INSTALL_FILES ${ELFDIR}/libelf.so*)
131     message(STATUS "Libelf is ${LIBELF_LIBRARIES}")
132     message(STATUS "Installing ${LIBELF_INSTALL_FILES} from ${ELFDIR}")
133     install (FILES ${LIBELF_INSTALL_FILES}
134       DESTINATION "${INSTALL_LIB_DIR}")
135   endif()
136   if(NOT LIBDWARF_FOUND)
137     message(STATUS "Installing ${LIBDWARF_LIBRARIES}")
138     install (FILES ${LIBDWARF_LIBRARIES}
139       DESTINATION "${INSTALL_LIB_DIR}")
140   endif()
141 endif()
142