Remove unused rpc/xdr references.
[dyninst.git] / cmake / packages.cmake
1 if (UNIX)
2   find_package (LibDwarf)
3   find_package (LibElf)
4
5   if(NOT LIBELF_FOUND OR NOT LIBDWARF_FOUND)
6     message(STATUS "Attempting to build elfutils as external project")
7     cmake_minimum_required (VERSION 2.8.11)
8     include(ExternalProject)
9     ExternalProject_Add(LibElf
10       PREFIX ${CMAKE_BINARY_DIR}/elfutils
11       URL https://sourceware.org/elfutils/ftp/0.168/elfutils-0.168.tar.bz2
12       CONFIGURE_COMMAND CFLAGS=-g <SOURCE_DIR>/configure --enable-shared --prefix=${CMAKE_BINARY_DIR}/elfutils
13       BUILD_COMMAND make
14       INSTALL_COMMAND make install
15       )
16     set(LIBELF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/elfutils/include)
17     set(LIBELF_LIBRARIES ${CMAKE_BINARY_DIR}/elfutils/lib/libelf.so)
18     set(LIBDWARF_INCLUDE_DIR ${CMAKE_BINARY_DIR}/elfutils/include)
19     set(LIBDWARF_LIBRARIES ${CMAKE_BINARY_DIR}/elfutils/lib/libdw.so)
20     set(SHOULD_INSTALL_LIBELF 1)
21   else()
22     set(SHOULD_INSTALL_LIBELF 0)
23   endif()
24
25   add_library(libelf_imp SHARED IMPORTED)
26   set_property(TARGET libelf_imp
27     PROPERTY IMPORTED_LOCATION ${LIBELF_LIBRARIES})
28   if(NOT LIBELF_FOUND)
29     add_dependencies(libelf_imp LibElf)
30   endif()
31
32   add_library(libdwarf_imp SHARED IMPORTED)
33   set_property(TARGET libdwarf_imp 
34     PROPERTY IMPORTED_LOCATION ${LIBDWARF_LIBRARIES})
35   if(NOT LIBDWARF_FOUND)
36     add_dependencies(libdwarf_imp LibDwarf)
37   endif()
38
39   if (NOT USE_GNU_DEMANGLER)
40     find_package (LibIberty)
41
42     if(NOT IBERTY_FOUND)
43       cmake_minimum_required (VERSION 2.8.11)
44       include(ExternalProject)
45       ExternalProject_Add(LibIberty
46         PREFIX ${CMAKE_BINARY_DIR}/binutils
47         URL http://ftp.gnu.org/gnu/binutils/binutils-2.23.tar.gz
48         CONFIGURE_COMMAND env CFLAGS=${CMAKE_C_FLAGS}\ -fPIC CPPFLAGS=-fPIC PICFLAG=-fPIC <SOURCE_DIR>/libiberty/configure --prefix=${CMAKE_BINARY_DIR}/libiberty --enable-shared
49         BUILD_COMMAND make all
50         INSTALL_DIR ${CMAKE_BINARY_DIR}/libiberty
51         INSTALL_COMMAND install <BINARY_DIR>/libiberty.a <INSTALL_DIR>
52         )
53       set(IBERTY_LIBRARIES ${CMAKE_BINARY_DIR}/libiberty/libiberty.a)
54       set(IBERTY_FOUND TRUE)
55       set(IBERTY_BUILD TRUE)
56     endif()
57
58     message(STATUS "Using libiberty ${IBERTY_LIBRARIES}")
59     add_library(libiberty_imp STATIC IMPORTED)
60     set_property(TARGET libiberty_imp
61       PROPERTY IMPORTED_LOCATION ${IBERTY_LIBRARIES})
62     if(IBERTY_BUILD)
63       add_dependencies(libiberty_imp LibIberty)
64     endif()
65   endif()
66
67   find_package (ThreadDB)
68   include_directories (
69     ${LIBELF_INCLUDE_DIR}
70     ${LIBDWARF_INCLUDE_DIR}
71     )
72 endif()
73
74 if (PLATFORM MATCHES "bgq")
75   # Not a find per se, just a magic include line
76   set (PATH_BGQ "/bgsys/drivers/ppcfloor" CACHE STRING "Path to BG/Q include files")
77   if (NOT (PATH_BGQ STREQUAL ""))
78     include_directories (${PATH_BGQ})
79   endif()
80 endif()
81
82
83 # UPDATE this for newer versions of Boost if you're using
84 # an older CMake and it complains that it can't find Boost
85 set(Boost_ADDITIONAL_VERSIONS "1.47" "1.47.0" "1.48" "1.48.0" "1.49" "1.49.0"
86   "1.50" "1.50.0" "1.51" "1.51.0" "1.52" "1.52.0"
87   "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"
88         "1.60" "1.60.0" "1.61" "1.61.0" "1.62" "1.62.0")
89
90 # set (Boost_DEBUG ON)
91 set (PATH_BOOST "/usr" CACHE STRING "Path to boost")
92
93 set(Boost_USE_MULTITHREADED ON)
94 set(Boost_USE_STATIC_RUNTIME OFF)
95
96 if (NOT ("${Boost_NO_BOOST_CMAKE}" STREQUAL "OFF"))
97   message(STATUS "Disabling Boost's own CMake--known buggy in many cases")
98   set(Boost_NO_BOOST_CMAKE ON)
99 endif()
100 if (NOT ("${PATH_BOOST}" STREQUAL ""))
101   set (CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} ${PATH_BOOST}/lib ${PATH_BOOST}/lib64)
102   set (CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} ${PATH_BOOST}/include)
103 endif()
104
105 # Boost 1.40/1.41 are not compatible with each other
106 # so ensure that we don't mix incompatible headers with
107 # the thread library
108 #set (BOOST_MIN_VERSION 1.41.0)
109
110 if(DEFINED PATH_BOOST OR 
111            DEFINED Boost_INCLUDE_DIR OR 
112            DEFINED Boost_LIBRARY_DIR)
113   set(Boost_NO_SYSTEM_PATHS ON)
114 endif()
115
116
117 find_package (Boost ${BOOST_MIN_VERSION} COMPONENTS thread system date_time)
118
119
120 if(NOT Boost_FOUND)
121   set (BOOST_ARGS
122           --with-system
123           --with-thread
124           --with-date_time
125           --ignore-site-config
126           --link=static
127           --runtime-link=shared
128           --layout=tagged
129           --threading=multi)
130   set(BOOST_BUILD "./b2")
131   if(WIN32)
132     set(BOOST_BOOTSTRAP call bootstrap.bat)
133     set(BOOST_BASE boost/src/Boost)
134     if(CMAKE_SIZEOF_VOID_P STREQUAL "8")
135           list(APPEND BOOST_ARGS address-model=64)
136     endif()
137   else()
138     set(BOOST_BOOTSTRAP "./bootstrap.sh")
139     set(BOOST_BASE boost/src/boost)
140     # We need to build both debug/release on windows as we don't use CMAKE_BUILD_TYPE
141     if(CMAKE_BUILD_TYPE STREQUAL "Debug")
142       list(APPEND BOOST_ARGS variant=debug)
143     else()
144       list(APPEND BOOST_ARGS variant=release)
145     endif()
146   endif()
147
148   message(STATUS "No boost found, attempting to build as external project")
149   cmake_minimum_required (VERSION 2.8.11)
150   include(ExternalProject)
151   ExternalProject_Add(boost
152     PREFIX ${CMAKE_BINARY_DIR}/boost
153     URL http://downloads.sourceforge.net/project/boost/boost/1.61.0/boost_1_61_0.zip
154     URL_MD5 015ae4afa6f3e597232bfe1dab949ace
155           BUILD_IN_SOURCE 1
156     CONFIGURE_COMMAND ${BOOST_BOOTSTRAP} --prefix=${CMAKE_INSTALL_PREFIX}
157     BUILD_COMMAND ${BOOST_BUILD} ${BOOST_ARGS} stage
158     INSTALL_COMMAND ""
159     )
160   set(Boost_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${BOOST_BASE})
161   set(Boost_LIBRARY_DIRS ${CMAKE_BINARY_DIR}/${BOOST_BASE}/stage/lib)
162   if(MSVC)
163     # We need to specify different library names for debug vs release
164     set(Boost_LIBRARIES optimized libboost_thread-mt debug libboost_thread-mt-gd)
165     list(APPEND Boost_LIBRARIES optimized libboost_system-mt debug libboost_system-mt-gd)
166     list(APPEND Boost_LIBRARIES optimized libboost_date_time-mt debug libboost_date_time-mt-gd)
167   else()
168     set(Boost_LIBRARIES boost_thread boost_system boost_date_time)
169   endif()
170 endif()
171
172 link_directories ( ${Boost_LIBRARY_DIRS} )
173
174 include_directories (
175   ${Boost_INCLUDE_DIRS}
176   )
177 add_definitions(-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
178 message(STATUS "Boost includes: ${Boost_INCLUDE_DIRS}")
179 message(STATUS "Boost library dirs: ${Boost_LIBRARY_DIRS}")
180 message(STATUS "Boost thread library: ${Boost_THREAD_LIBRARY}")
181 message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
182
183 include(${DYNINST_ROOT}/cmake/CheckCXX11Features.cmake)
184 if(NOT HAS_CXX11_AUTO)
185   message(FATAL_ERROR "No support for C++11 auto found. Dyninst requires this compiler feature.")
186 else()
187   message(STATUS "C++11 support found, required flags are: ${CXX11_COMPILER_FLAGS}")
188 endif()
189
190 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")