Support for conversion from Instruction API objects to Rose SgAsmInstruction objects...
[dyninst.git] / cmake / packages.cmake
1 if (UNIX)
2   find_package (LibElf)
3   if(NOT LIBELF_FOUND)
4     message(STATUS "No libelf found, attempting to build as external project")
5     cmake_minimum_required (VERSION 2.8.11)
6     include(ExternalProject)
7     ExternalProject_Add(LibElf
8       PREFIX ${CMAKE_BINARY_DIR}/libelf
9       URL http://www.mr511.de/software/libelf-0.8.13.tar.gz
10       CONFIGURE_COMMAND <SOURCE_DIR>/configure --enable-shared --prefix=${CMAKE_BINARY_DIR}/libelf
11       BUILD_COMMAND make
12       INSTALL_COMMAND make install
13       )
14     set(LIBELF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libelf/include)
15     set(LIBELF_LIBRARIES ${CMAKE_BINARY_DIR}/libelf/lib/libelf.so)
16     set(SHOULD_INSTALL_LIBELF 1)
17   else()
18     set(SHOULD_INSTALL_LIBELF 0)
19   endif()
20
21   add_library(libelf_imp SHARED IMPORTED)
22   set_property(TARGET libelf_imp
23     PROPERTY IMPORTED_LOCATION ${LIBELF_LIBRARIES}) 
24
25   find_package (LibDwarf)
26
27   if(NOT LIBDWARF_FOUND)
28     message(STATUS "No libdwarf found, attempting to build as external project")
29     cmake_minimum_required (VERSION 2.8.11)
30     include(ExternalProject)
31     ExternalProject_Add(LibDwarf
32       PREFIX ${CMAKE_BINARY_DIR}/libdwarf
33       DEPENDS libelf_imp
34       # URL http://reality.sgiweb.org/davea/libdwarf-20130126.tar.gz
35       # URL http://sourceforge.net/p/libdwarf/code/ci/20130126/tarball
36       URL http://www.paradyn.org/libdwarf/libdwarf-20130126.tar.gz
37       # GIT_REPOSITORY git://git.code.sf.net/p/libdwarf/code libdwarf-code
38       # GIT_TAG 20130126
39       CONFIGURE_COMMAND CFLAGS=-I${LIBELF_INCLUDE_DIR} LDFLAGS=-L${CMAKE_BINARY_DIR}/libelf/lib <SOURCE_DIR>/libdwarf/configure --enable-shared
40       BUILD_COMMAND make
41       INSTALL_DIR ${CMAKE_BINARY_DIR}/libdwarf
42       INSTALL_COMMAND mkdir -p <INSTALL_DIR>/include && mkdir -p <INSTALL_DIR>/lib && install <SOURCE_DIR>/libdwarf/libdwarf.h <INSTALL_DIR>/include && install <SOURCE_DIR>/libdwarf/dwarf.h <INSTALL_DIR>/include && install <BINARY_DIR>/libdwarf.so <INSTALL_DIR>/lib
43       )
44     add_dependencies(LibDwarf libelf_imp)
45     set(LIBDWARF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/libdwarf/include)
46     set(LIBDWARF_LIBRARIES ${CMAKE_BINARY_DIR}/libdwarf/lib/libdwarf.so)
47   else()
48     # Unfortunately, libdwarf doesn't always link to libelf itself.
49     # (e.g. https://bugzilla.redhat.com/show_bug.cgi?id=1061432)
50     set(LIBDWARF_LIBRARIES ${LIBDWARF_LIBRARIES} ${LIBELF_LIBRARIES})
51   endif()
52
53   add_library(libdwarf_imp SHARED IMPORTED)
54   set_property(TARGET libdwarf_imp 
55     PROPERTY IMPORTED_LOCATION ${LIBDWARF_LIBRARIES})
56
57   if (NOT USE_GNU_DEMANGLER)
58     find_package (LibIberty)
59
60     if(NOT IBERTY_FOUND)
61       cmake_minimum_required (VERSION 2.8.11)
62       include(ExternalProject)
63       ExternalProject_Add(LibIberty
64         PREFIX ${CMAKE_BINARY_DIR}/binutils
65         URL http://ftp.gnu.org/gnu/binutils/binutils-2.23.tar.gz
66         CONFIGURE_COMMAND CFLAGS=-fPIC CPPFLAGS=-fPIC PICFLAG=-fPIC <SOURCE_DIR>/libiberty/configure --prefix=${CMAKE_BINARY_DIR}/libiberty --enable-shared
67         BUILD_COMMAND make all
68         INSTALL_DIR ${CMAKE_BINARY_DIR}/libiberty
69         INSTALL_COMMAND install <BINARY_DIR>/libiberty.a <INSTALL_DIR>
70         )
71       set(IBERTY_LIBRARIES ${CMAKE_BINARY_DIR}/libiberty/libiberty.a)
72     endif()
73
74     message(STATUS "Using libiberty ${IBERTY_LIBRARIES}")
75     add_library(libiberty_imp STATIC IMPORTED)
76     set_property(TARGET libiberty_imp
77       PROPERTY IMPORTED_LOCATION ${IBERTY_LIBRARIES})
78   endif()
79
80   find_package (ThreadDB)
81   include_directories (
82     ${LIBELF_INCLUDE_DIR}
83     ${LIBDWARF_INCLUDE_DIR}
84     )
85 elseif(WIN32)
86   find_package (DIASDK REQUIRED)
87   include_directories(${DIASDK_INCLUDE_DIR})
88 endif()
89
90 if (PLATFORM MATCHES "bgq")
91   # Not a find per se, just a magic include line
92   set (PATH_BGQ "/bgsys/drivers/ppcfloor" CACHE STRING "Path to BG/Q include files")
93   if (NOT (PATH_BGQ STREQUAL ""))
94     include_directories (${PATH_BGQ})
95   endif()
96 endif()
97
98
99 # UPDATE this for newer versions of Boost if you're using
100 # an older CMake and it complains that it can't find Boost
101 set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48" "1.48.0" "1.49" "1.49.0"
102   "1.50" "1.50.0" "1.51" "1.51.0" "1.52" "1.52.0"
103   "1.53" "1.53.0" "1.54" "1.54.0" "1.55" "1.55.0" "1.56" "1.56.0" "1.57" "1.57.0" "1.58" "1.58.0" "1.59" "1.59.0")
104
105 # set (Boost_DEBUG ON)
106 set (PATH_BOOST "/usr" CACHE STRING "Path to boost")
107
108 set(Boost_USE_MULTITHREADED ON)
109 set(Boost_USE_STATIC_RUNTIME OFF)
110
111 if (NOT ("${Boost_NO_BOOST_CMAKE}" STREQUAL "OFF"))
112   message(STATUS "Disabling Boost's own CMake--known buggy in many cases")
113   set(Boost_NO_BOOST_CMAKE ON)
114 endif()
115 if (NOT ("${PATH_BOOST}" STREQUAL ""))
116   set (CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PATH_BOOST}/lib ${PATH_BOOST}/lib64)
117   set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${PATH_BOOST}/include)
118 endif()
119
120 # Boost 1.40/1.41 are not compatible with each other
121 # so ensure that we don't mix incompatible headers with
122 # the thread library
123 #set (BOOST_MIN_VERSION 1.41.0)
124
125 if(DEFINED PATH_BOOST OR 
126            DEFINED Boost_INCLUDE_DIR OR 
127            DEFINED Boost_LIBRARY_DIR)
128   set(Boost_NO_SYSTEM_PATHS ON)
129 endif()
130
131 find_package (Boost ${BOOST_MIN_VERSION} REQUIRED COMPONENTS thread system)
132
133 link_directories ( ${Boost_LIBRARY_DIRS} )
134
135 include_directories (
136   ${Boost_INCLUDE_DIRS}
137   )
138
139 message(STATUS "Boost includes: ${Boost_INCLUDE_DIRS}")
140 message(STATUS "Boost library dirs: ${Boost_LIBRARY_DIRS}")
141 message(STATUS "Boost thread library: ${Boost_THREAD_LIBRARY}")
142 message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
143
144 include(${DYNINST_ROOT}/cmake/CheckCXX11Features.cmake)
145 if(NOT HAS_CXX11_AUTO)
146   message(FATAL_ERROR "No support for C++11 auto found. Dyninst requires this compiler feature.")
147 else()
148   message(STATUS "C++11 support found, required flags are: ${CXX11_COMPILER_FLAGS}")
149 endif()
150
151 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")