Update version number to 10.1.0
[dyninst.git] / cmake / shared.cmake
1 set (DYNINST_MAJOR_VERSION 10)
2 set (DYNINST_MINOR_VERSION 1)
3 set (DYNINST_PATCH_VERSION 0)
4
5 set (SOVERSION "${DYNINST_MAJOR_VERSION}.${DYNINST_MINOR_VERSION}")
6 set (LIBVERSION "${SOVERSION}.${DYNINST_PATCH_VERSION}")
7 set (DYNINST_VERSION "${LIBVERSION}")
8
9 if(CMAKE_CONFIGURATION_TYPES)
10   set(CMAKE_CONFIGURATION_TYPES Debug Release)
11   set(CMAKE_CONFIGURATION_TYPES "${CMAKE_CONFIGURATION_TYPES}" CACHE STRING
12   "Reset the available configurations to exclude MinSizeRel and RelWithDebugInfo" FORCE)
13 endif()
14
15 if (LIGHTWEIGHT_SYMTAB)
16   set(SYMREADER symLite)
17 else()
18   set(SYMREADER symtabAPI)
19 endif()
20
21 # Link libraries privately when possible
22 function (target_link_private_libraries target)
23   if(${CMAKE_VERSION} VERSION_LESS "2.8.7")
24     target_link_libraries (${target} ${ARGN})
25   else()
26     target_link_libraries (${target} LINK_PRIVATE ${ARGN})
27   endif()
28 endfunction ()
29
30 set(ALL_DYNINST_TARGETS "" CACHE INTERNAL "")
31
32 function (dyninst_library target)
33   add_library (${target} ${SRC_LIST})
34   # add boost as a universal dependencies for all sub libraries
35   if(TARGET boost)
36     add_dependencies (${target} boost)
37   endif()
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 include (${DYNINST_ROOT}/cmake/platform.cmake)
85 if (NOT ${PROJECT_NAME} MATCHES DyninstRT)
86 include (${DYNINST_ROOT}/cmake/packages.cmake)
87 endif()
88 include (${DYNINST_ROOT}/cmake/cap_arch_def.cmake)
89 include (${DYNINST_ROOT}/cmake/visibility.cmake)
90 include (${DYNINST_ROOT}/cmake/warnings.cmake)
91 include (${DYNINST_ROOT}/cmake/options.cmake)
92 include (${DYNINST_ROOT}/cmake/optimization.cmake)
93 include (${DYNINST_ROOT}/cmake/endian.cmake)
94
95 # Check for cotire-gcc compatibility
96 IF(CMAKE_COMPILER_IS_GNUCC)
97     execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
98     string(REGEX MATCHALL "[0-9]+" GCC_VERSION_COMPONENTS ${GCC_VERSION})
99     IF(GCC_VERSION VERSION_LESS 4.5)
100         SET(USE_COTIRE OFF)
101     ENDIF()
102 ENDIF(CMAKE_COMPILER_IS_GNUCC)
103
104 # If we're compiling for unix, cotire only supports Intel, GCC and Clang.
105 IF (UNIX AND NOT ((${CMAKE_CXX_COMPILER_ID} MATCHES Clang) OR (${CMAKE_CXX_COMPILER_ID} MATCHES GNU) OR (${CMAKE_CXX_COMPILER_ID} MATCHES Intel)))
106         set(USE_COTIRE OFF)
107 ENDIF()
108
109 # Make sure our CMake version is actually supported by cotire
110 IF(CMAKE_VERSION VERSION_LESS 2.8.12)
111     SET(USE_COTIRE OFF)
112 ENDIF()
113
114 if (USE_COTIRE)
115     include (${DYNINST_ROOT}/cmake/cotire.cmake)
116     set_directory_properties(PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
117 endif()
118
119
120 set (BUILD_SHARED_LIBS ON)
121
122 set (INSTALL_BIN_DIR bin CACHE PATH "Installation directory for executables")
123 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
124 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
125 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
126 set (INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for manuals")
127
128 # Make the above absolute paths if necessary
129 foreach (p BIN LIB INCLUDE CMAKE)
130   set (var INSTALL_${p}_DIR)
131   if (NOT IS_ABSOLUTE "${${var}}")
132      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
133   endif()
134 endforeach()
135
136 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
137   add_definitions(-DWIN32_LEAN_AND_MEAN)
138   if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 19)
139     add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
140   else()
141     add_definitions(-Dsnprintf=_snprintf)
142   endif()
143 endif()
144
145 set (USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
146 if (NOT ("${USE_CXX11_ABI}" STREQUAL ""))
147   if (${USE_CXX11_ABI})
148     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
149   else()
150     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
151   endif()
152 endif()
153
154 #
155 # DyninstConfig.cmake
156
157 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
158
159 # For the install tree
160 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
161
162 # set default configuration type
163
164 if (NOT CMAKE_BUILD_TYPE)
165    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
166        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
167 endif()
168