Deleted the old code block
[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 (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
98 # Check for cotire-gcc compatibility
99 set(USE_COTIRE true)
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 false)
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}" STREQUAL "Clang") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")))
110         set(USE_COTIRE false)
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 false)
116 ENDIF()
117
118 if (USE_COTIRE)
119     include (${DYNINST_ROOT}/cmake/cotire.cmake)
120 endif()
121
122 set_directory_properties(PROPERTIES COTIRE_ADD_UNITY_BUILD FALSE)
123
124 set (BUILD_SHARED_LIBS ON)
125
126 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
127 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
128 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
129 set (INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for manuals")
130
131 # Make the above absolute paths if necessary
132 foreach (p LIB INCLUDE CMAKE)
133   set (var INSTALL_${p}_DIR)
134   if (NOT IS_ABSOLUTE "${${var}}")
135      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
136   endif()
137 endforeach()
138
139 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
140   add_definitions(-DWIN32_LEAN_AND_MEAN)
141   if (CMAKE_C_COMPILER_VERSION VERSION_GREATER 19)
142     add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
143   else()
144     add_definitions(-Dsnprintf=_snprintf)
145   endif()
146 endif()
147
148 set (USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
149 if (NOT ("${USE_CXX11_ABI}" STREQUAL ""))
150   if (${USE_CXX11_ABI})
151     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
152   else()
153     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
154   endif()
155 endif()
156
157 #
158 # DyninstConfig.cmake
159
160 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
161
162 # For the install tree
163 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
164
165 # set default configuration type
166
167 if (NOT CMAKE_BUILD_TYPE)
168    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
169        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
170 endif()