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