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