check and report endianness with cmake
[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 #set(USE_GNU_DEMANGLER 1)
87
88 set (ENABLE_LTO FALSE CACHE BOOL "Enable Link-Time Optimization")
89
90 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DYNINST_ROOT}/cmake/Modules")
91 include (${DYNINST_ROOT}/cmake/platform.cmake)
92 if (NOT ${PROJECT_NAME} MATCHES DyninstRT)
93 include (${DYNINST_ROOT}/cmake/packages.cmake)
94 endif()
95 include (${DYNINST_ROOT}/cmake/cap_arch_def.cmake)
96 include (${DYNINST_ROOT}/cmake/visibility.cmake)
97 include (${DYNINST_ROOT}/cmake/warnings.cmake)
98 include (${DYNINST_ROOT}/cmake/options.cmake)
99 include (${DYNINST_ROOT}/cmake/optimization.cmake)
100 include (${DYNINST_ROOT}/cmake/endian.cmake)
101
102 # Check for cotire-gcc compatibility
103 set(USE_COTIRE false)
104 IF(CMAKE_COMPILER_IS_GNUCC)
105     execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
106     string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
107     IF(GCC_VERSION VERSION_LESS 4.5)
108         SET(USE_COTIRE false)
109     ENDIF()
110 ENDIF(CMAKE_COMPILER_IS_GNUCC)
111
112 # If we're compiling for unix, cotire only supports Intel, GCC and Clang.
113 IF (UNIX AND NOT ((${CMAKE_CXX_COMPILER_ID} MATCHES Clang) OR (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) OR (${CMAKE_CXX_COMPILER_ID} MATCHES Intel)))
114         set(USE_COTIRE false)
115 ENDIF()
116
117 # Make sure our CMake version is actually supported by cotire
118 IF(CMAKE_VERSION VERSION_LESS 2.8.12)
119     SET(USE_COTIRE false)
120 ENDIF()
121
122 if (USE_COTIRE)
123     include (${DYNINST_ROOT}/cmake/cotire.cmake)
124 endif()
125
126 set_directory_properties(PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
127
128 set (BUILD_SHARED_LIBS ON)
129
130 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
131 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
132 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
133 set (INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for manuals")
134
135 # Make the above absolute paths if necessary
136 foreach (p LIB INCLUDE CMAKE)
137   set (var INSTALL_${p}_DIR)
138   if (NOT IS_ABSOLUTE "${${var}}")
139      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
140   endif()
141 endforeach()
142
143 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
144   add_definitions(-DWIN32_LEAN_AND_MEAN)
145   if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 19)
146     add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
147   else()
148     add_definitions(-Dsnprintf=_snprintf)
149   endif()
150 endif()
151
152 set (USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
153 if (NOT ("${USE_CXX11_ABI}" STREQUAL ""))
154   if (${USE_CXX11_ABI})
155     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
156   else()
157     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
158   endif()
159 endif()
160
161 #
162 # DyninstConfig.cmake
163
164 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
165
166 # For the install tree
167 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
168
169 # set default configuration type
170
171 if (NOT CMAKE_BUILD_TYPE)
172    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
173        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
174 endif()
175
176 # There are broken versions of MSVC that won't handle variadic templates correctly (despite the C++11 test case passing).
177 # Just build vanilla versions, boost can handle it.
178 if (MSVC)
179   add_definitions(-DBOOST_NO_CXX11_VARIADIC_TEMPLATES)
180 endif()