Modifying cmake configuration to compile and install TBB.
[dyninst.git] / cmake / shared.cmake
1 set (DYNINST_MAJOR_VERSION 9)
2 set (DYNINST_MINOR_VERSION 3)
3 set (DYNINST_PATCH_VERSION 2)
4
5 # Debugging
6 set(Boost_DEBUG 1)
7
8 add_definitions(-DBOOST_ALL_NO_LIB=1)
9 set (SOVERSION "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}")
10 set (LIBVERSION "${SOVERSION}.${DYNINST_PATCH_VERSION}")
11 set (DYNINST_VERSION "${LIBVERSION}")
12
13 if(CMAKE_CONFIGURATION_TYPES)
14   set(CMAKE_CONFIGURATION_TYPES Debug Release)
15   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
16   "Reset the available configurations to exclude MinSizeRel and RelWithDebugInfo" FORCE)
17 endif()
18
19 if (LIGHTWEIGHT_SYMTAB)
20   set(SYMREADER symLite)
21 else()
22   set(SYMREADER symtabAPI)
23 endif()
24
25 # Link libraries privately when possible
26 function (target_link_private_libraries target)
27   if(${CMAKE_VERSION} VERSION_LESS "2.8.7")
28     target_link_libraries (${target} ${ARGN})
29   else()
30     target_link_libraries (${target} LINK_PRIVATE ${ARGN})
31   endif()
32 endfunction ()
33
34 set(ALL_DYNINST_TARGETS "" CACHE INTERNAL "")
35
36 function (dyninst_library target)
37   add_library (${target} ${SRC_LIST})
38   target_link_private_libraries (${target} ${ARGN})
39   FILE (GLOB headers "h/*.h" "${CMAKE_CURRENT_BINARY_DIR}/h/*.h")
40   set (ACTUAL_TARGETS ${target})
41   set (ALL_TARGETS "${ARGN};${target}")
42   if(${ENABLE_STATIC_LIBS})
43     set (ACTUAL_TARGETS ${ACTUAL_TARGETS} ${target}_static)
44     add_library (${target}_static STATIC ${SRC_LIST})
45   endif()
46   message(STATUS "Building ${ACTUAL_TARGETS}...")
47   set_target_properties (${ACTUAL_TARGETS} PROPERTIES PUBLIC_HEADER "${headers}")
48   set_target_properties (${ACTUAL_TARGETS} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
49   set_target_properties (${target} PROPERTIES SOVERSION ${SOVERSION} VERSION ${LIBVERSION} CLEAN_DIRECT_OUTPUT 1)
50   set (INSTALL_TARGETS ${ACTUAL_TARGETS})
51   foreach (dep ${ARGN})
52     message(STATUS "Processing dependent target ${dep}...")
53     if(TARGET ${dep})
54         get_target_property(dep_dir ${dep} LIBRARY_OUTPUT_DIRECTORY)
55         if(EXISTS ${dep_dir} AND IS_DIRECTORY ${dep_dir})
56           message(STATUS "Found dependency location ${dep_dir}")
57           install(SCRIPT ${dep_dir}/cmake_install.cmake)
58         endif()
59     endif()
60   endforeach()
61   install (TARGETS ${INSTALL_TARGETS}
62     EXPORT ${target}Targets
63     COMPONENT ${target}
64     RUNTIME DESTINATION ${INSTALL_LIB_DIR}
65     LIBRARY DESTINATION ${INSTALL_LIB_DIR}
66     ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
67     PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
68   add_custom_target(${target}-install
69     DEPENDS ${target}
70     COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
71     )
72   set(ALL_DYNINST_TARGETS "${ALL_DYNINST_TARGETS};${target}" CACHE INTERNAL "")
73   install (EXPORT ${target}Targets
74     DESTINATION "${INSTALL_CMAKE_DIR}")
75   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}Config.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY)
76   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}ConfigVersion.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake" @ONLY)
77   install (FILES
78     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
79     "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake"
80     DESTINATION "${INSTALL_CMAKE_DIR}")
81 endfunction()
82
83
84
85 #Change to switch between libiberty/libstdc++ demangler
86
87 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DYNINST_ROOT}/cmake/Modules")
88 include (${DYNINST_ROOT}/cmake/platform.cmake)
89 if (NOT ${PROJECT_NAME} MATCHES DyninstRT)
90 include (${DYNINST_ROOT}/cmake/packages.cmake)
91 endif()
92 include (${DYNINST_ROOT}/cmake/cap_arch_def.cmake)
93 include (${DYNINST_ROOT}/cmake/visibility.cmake)
94 include (${DYNINST_ROOT}/cmake/warnings.cmake)
95 include (${DYNINST_ROOT}/cmake/options.cmake)
96 include (${DYNINST_ROOT}/cmake/optimization.cmake)
97 include (${DYNINST_ROOT}/cmake/endian.cmake)
98
99 # Check for cotire-gcc compatibility
100 IF(CMAKE_COMPILER_IS_GNUCC)
101     execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
102     string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
103     IF(GCC_VERSION VERSION_LESS 4.5)
104         SET(USE_COTIRE OFF)
105     ENDIF()
106 ENDIF(CMAKE_COMPILER_IS_GNUCC)
107
108 # If we're compiling for unix, cotire only supports Intel, GCC and Clang.
109 IF (UNIX AND NOT ((${CMAKE_CXX_COMPILER_ID} MATCHES Clang) OR (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) OR (${CMAKE_CXX_COMPILER_ID} MATCHES Intel)))
110         set(USE_COTIRE OFF)
111 ENDIF()
112
113 # Make sure our CMake version is actually supported by cotire
114 IF(CMAKE_VERSION VERSION_LESS 2.8.12)
115     SET(USE_COTIRE OFF)
116 ENDIF()
117
118 if (USE_COTIRE)
119     include (${DYNINST_ROOT}/cmake/cotire.cmake)
120     set_directory_properties(PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
121 endif()
122
123
124 set (BUILD_SHARED_LIBS ON)
125
126 set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
127 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
128 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
129 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
130 set (INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for manuals")
131
132 # Make the above absolute paths if necessary
133 foreach (p BIN LIB INCLUDE CMAKE)
134   set (var INSTALL_${p}_DIR)
135   if (NOT IS_ABSOLUTE "${${var}}")
136      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
137   endif()
138 endforeach()
139
140 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
141   add_definitions(-DWIN32_LEAN_AND_MEAN)
142   if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 19)
143     add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
144   else()
145     add_definitions(-Dsnprintf=_snprintf)
146   endif()
147 endif()
148
149 set (USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
150 if (NOT ("${USE_CXX11_ABI}" STREQUAL ""))
151   if (${USE_CXX11_ABI})
152     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
153   else()
154     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
155   endif()
156 endif()
157
158 #
159 # DyninstConfig.cmake
160
161 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
162
163 # For the install tree
164 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
165
166 # set default configuration type
167
168 if (NOT CMAKE_BUILD_TYPE)
169    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
170        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
171 endif()
172
173 # There are broken versions of MSVC that won't handle variadic templates correctly (despite the C++11 test case passing).
174 # Just build vanilla versions, boost can handle it.
175 if (MSVC)
176   add_definitions(-DBOOST_NO_CXX11_VARIADIC_TEMPLATES)
177 endif()