bill's changes to parallelize symtab.
[dyninst.git] / cmake / packages.cmake
1 if (UNIX)
2   find_package (LibDwarf)
3   find_package (LibElf)
4   find_package(TBB REQUIRED)
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 timer filesystem)
118 find_library(PROFILER_LIBRARIES profiler /p/paradyn/packages/gperftools/lib)
119
120 if(NOT Boost_FOUND)
121   set (BOOST_ARGS
122           --with-system
123           --with-thread
124           --with-date_time
125           --with-filesystem
126           --with-timer
127           --ignore-site-config
128           --link=static
129           --runtime-link=shared
130           --layout=tagged
131           --threading=multi)
132   set(BOOST_BUILD "./b2")
133   if(WIN32)
134     set(BOOST_BOOTSTRAP call bootstrap.bat)
135     set(BOOST_BASE boost/src/Boost)
136     if(CMAKE_SIZEOF_VOID_P STREQUAL "8")
137           list(APPEND BOOST_ARGS address-model=64)
138     endif()
139   else()
140     set(BOOST_BOOTSTRAP "./bootstrap.sh")
141     set(BOOST_BASE boost/src/boost)
142     # We need to build both debug/release on windows as we don't use CMAKE_BUILD_TYPE
143     if(CMAKE_BUILD_TYPE STREQUAL "Debug")
144       list(APPEND BOOST_ARGS variant=debug)
145     else()
146       list(APPEND BOOST_ARGS variant=release)
147     endif()
148   endif()
149
150   message(STATUS "No boost found, attempting to build as external project")
151   cmake_minimum_required (VERSION 2.8.11)
152   include(ExternalProject)
153   ExternalProject_Add(boost
154     PREFIX ${CMAKE_BINARY_DIR}/boost
155     URL http://downloads.sourceforge.net/project/boost/boost/1.61.0/boost_1_61_0.zip
156     URL_MD5 015ae4afa6f3e597232bfe1dab949ace
157           BUILD_IN_SOURCE 1
158     CONFIGURE_COMMAND ${BOOST_BOOTSTRAP} --prefix=${CMAKE_INSTALL_PREFIX}
159     BUILD_COMMAND ${BOOST_BUILD} ${BOOST_ARGS} stage
160     INSTALL_COMMAND ""
161     )
162   set(Boost_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/${BOOST_BASE})
163   set(Boost_LIBRARY_DIRS ${CMAKE_BINARY_DIR}/${BOOST_BASE}/stage/lib)
164   if(MSVC)
165     # We need to specify different library names for debug vs release
166     set(Boost_LIBRARIES optimized libboost_thread-mt debug libboost_thread-mt-gd)
167     list(APPEND Boost_LIBRARIES optimized libboost_system-mt debug libboost_system-mt-gd)
168     list(APPEND Boost_LIBRARIES optimized libboost_date_time-mt debug libboost_date_time-mt-gd)
169   else()
170     set(Boost_LIBRARIES boost_thread boost_system boost_date_time boost_filesystem)
171   endif()
172 endif()
173
174 link_directories ( ${Boost_LIBRARY_DIRS} )
175
176 include_directories (
177   ${Boost_INCLUDE_DIRS}
178   )
179 add_definitions(-DBOOST_MULTI_INDEX_DISABLE_SERIALIZATION)
180 message(STATUS "Boost includes: ${Boost_INCLUDE_DIRS}")
181 message(STATUS "Boost library dirs: ${Boost_LIBRARY_DIRS}")
182 message(STATUS "Boost thread library: ${Boost_THREAD_LIBRARY}")
183 message(STATUS "Boost libraries: ${Boost_LIBRARIES}")
184 find_package(Threads)
185 set(Boost_LIBRARIES ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
186
187 include(${DYNINST_ROOT}/cmake/CheckCXX11Features.cmake)
188 if(NOT HAS_CXX11_AUTO)
189   message(FATAL_ERROR "No support for C++11 auto found. Dyninst requires this compiler feature.")
190 else()
191   message(STATUS "C++11 support found, required flags are: ${CXX11_COMPILER_FLAGS}")
192 endif()
193
194 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CXX11_COMPILER_FLAGS}")
195 find_package(Cilk)
196 if(CILK_FOUND)
197   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CILK_DEFINITIONS}")
198 endif()