Support for conversion from Instruction API objects to Rose SgAsmInstruction objects...
[dyninst.git] / cmake / shared.cmake
1 set (DYNINST_MAJOR_VERSION 9)
2 set (DYNINST_MINOR_VERSION 1)
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 (LIGHTWEIGHT_SYMTAB)
13   set(SYMREADER symLite)
14 else()
15   set(SYMREADER symtabAPI)
16 endif()
17
18 # Link libraries privately when possible
19 function (target_link_private_libraries target)
20   if(${CMAKE_VERSION} VERSION_LESS "2.8.7")
21     target_link_libraries (${target} ${ARGN})
22   else()
23     target_link_libraries (${target} LINK_PRIVATE ${ARGN})
24   endif()
25 endfunction ()
26
27 set(ALL_DYNINST_TARGETS "" CACHE INTERNAL "")
28
29 function (dyninst_library target)
30   add_library (${target} ${SRC_LIST})
31   target_link_private_libraries (${target} ${ARGN})
32   FILE (GLOB headers "h/*.h" "${CMAKE_CURRENT_BINARY_DIR}/h/*.h")
33   set (ACTUAL_TARGETS ${target})
34   set (ALL_TARGETS "${ARGN};${target}")
35   if(${ENABLE_STATIC_LIBS})
36     set (ACTUAL_TARGETS ${ACTUAL_TARGETS} ${target}_static)
37     add_library (${target}_static STATIC ${SRC_LIST})
38   endif()
39   message(STATUS "Building ${ACTUAL_TARGETS}...")
40   set_target_properties (${ACTUAL_TARGETS} PROPERTIES PUBLIC_HEADER "${headers}")
41   set_target_properties (${ACTUAL_TARGETS} PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
42   set_target_properties (${target} PROPERTIES SOVERSION ${SOVERSION} VERSION ${LIBVERSION} CLEAN_DIRECT_OUTPUT 1)
43   set (INSTALL_TARGETS ${ACTUAL_TARGETS})
44   foreach (dep ${ARGN})
45     message(STATUS "Processing dependent target ${dep}...")
46     if(TARGET ${dep})
47         get_target_property(dep_dir ${dep} LIBRARY_OUTPUT_DIRECTORY)
48         if(EXISTS ${dep_dir} AND IS_DIRECTORY ${dep_dir})
49           message(STATUS "Found dependency location ${dep_dir}")
50           install(SCRIPT ${dep_dir}/cmake_install.cmake)
51         endif()
52     endif()
53   endforeach()
54   install (TARGETS ${INSTALL_TARGETS}
55     EXPORT ${target}Targets
56     COMPONENT ${target}
57     RUNTIME DESTINATION ${INSTALL_LIB_DIR}
58     LIBRARY DESTINATION ${INSTALL_LIB_DIR}
59     ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
60     PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
61   add_custom_target(${target}-install
62     DEPENDS ${target}
63     COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
64     )
65   set(ALL_DYNINST_TARGETS "${ALL_DYNINST_TARGETS};${target}" CACHE INTERNAL "")
66   install (EXPORT ${target}Targets
67     DESTINATION "${INSTALL_CMAKE_DIR}")
68   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}Config.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY)
69   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}ConfigVersion.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake" @ONLY)
70   install (FILES
71     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
72     "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake"
73     DESTINATION "${INSTALL_CMAKE_DIR}")
74 endfunction()
75
76
77
78 #Change to switch between libiberty/libstdc++ demangler
79 #set(USE_GNU_DEMANGLER 1)
80
81 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DYNINST_ROOT}/cmake/Modules")
82 include (${DYNINST_ROOT}/cmake/platform.cmake)
83 if (NOT ${PROJECT_NAME} MATCHES DyninstRT)
84 include (${DYNINST_ROOT}/cmake/packages.cmake)
85 endif()
86 include (${DYNINST_ROOT}/cmake/cap_arch_def.cmake)
87 include (${DYNINST_ROOT}/cmake/visibility.cmake)
88 include (${DYNINST_ROOT}/cmake/warnings.cmake)
89 include (${DYNINST_ROOT}/cmake/options.cmake)
90 include (${DYNINST_ROOT}/cmake/optimization.cmake)
91
92 set (BUILD_SHARED_LIBS ON)
93
94 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
95 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
96 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
97 set (INSTALL_DOC_DIR share/doc CACHE PATH "Installation directory for manuals")
98
99 # Make the above absolute paths if necessary
100 foreach (p LIB INCLUDE CMAKE)
101   set (var INSTALL_${p}_DIR)
102   if (NOT IS_ABSOLUTE "${${var}}")
103      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
104   endif()
105 endforeach()
106
107 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
108   if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19)
109     add_definitions(-D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1)
110   else()
111     add_definitions(-Dsnprintf=_snprintf)
112   endif()
113 endif()
114
115 set (USE_CXX11_ABI "" CACHE STRING "Override the default GNU C++11 ABI setting")
116 if (NOT ("${USE_CXX11_ABI}" STREQUAL ""))
117   if (${USE_CXX11_ABI})
118     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=1)
119   else()
120     add_definitions(-D_GLIBCXX_USE_CXX11_ABI=0)
121   endif()
122 endif()
123
124 #
125 # DyninstConfig.cmake
126
127 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
128
129 # For the install tree
130 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
131
132 # set default configuration type
133
134 if (NOT CMAKE_BUILD_TYPE)
135    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
136        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
137 endif()