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