Move docs back to main repository, with CMake targets for ${COMPONENT}-doc, automatic...
[dyninst.git] / cmake / shared.cmake
1 set (DYNINST_MAJOR_VERSION 9)
2 set (DYNINST_MINOR_VERSION 0)
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")
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     get_target_property(dep_dir ${dep} LIBRARY_OUTPUT_DIRECTORY)
47     if(EXISTS ${dep_dir} AND IS_DIRECTORY ${dep_dir})
48       message(STATUS "Found dependency location ${dep_dir}")
49       install(SCRIPT ${dep_dir}/cmake_install.cmake)
50     endif()
51   endforeach()
52   install (TARGETS ${INSTALL_TARGETS}
53     EXPORT ${target}Targets
54     COMPONENT ${target}
55     RUNTIME DESTINATION ${INSTALL_LIB_DIR}
56     LIBRARY DESTINATION ${INSTALL_LIB_DIR}
57     ARCHIVE DESTINATION ${INSTALL_LIB_DIR}
58     PUBLIC_HEADER DESTINATION ${INSTALL_INCLUDE_DIR})
59   add_custom_target(${target}-install
60     DEPENDS ${target}
61     COMMAND "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake"
62     )
63   set(ALL_DYNINST_TARGETS "${ALL_DYNINST_TARGETS};${target}" CACHE INTERNAL "")
64   install (EXPORT ${target}Targets
65     DESTINATION "${INSTALL_CMAKE_DIR}")
66   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}Config.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake" @ONLY)
67   configure_file("${DYNINST_ROOT}/cmake/${PROJECT_NAME}ConfigVersion.cmake.in" "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake" @ONLY)
68   install (FILES
69     "${PROJECT_BINARY_DIR}/${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}Config.cmake"
70     "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${PROJECT_NAME}ConfigVersion.cmake"
71     DESTINATION "${INSTALL_CMAKE_DIR}")
72 endfunction()
73
74
75
76 #Change to switch between libiberty/libstdc++ demangler
77 #set(USE_GNU_DEMANGLER 1)
78
79 set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${DYNINST_ROOT}/cmake/Modules")
80 include (${DYNINST_ROOT}/cmake/platform.cmake)
81 if (NOT ${PROJECT_NAME} MATCHES DyninstRT)
82 include (${DYNINST_ROOT}/cmake/packages.cmake)
83 endif()
84 include (${DYNINST_ROOT}/cmake/cap_arch_def.cmake)
85 include (${DYNINST_ROOT}/cmake/visibility.cmake)
86 include (${DYNINST_ROOT}/cmake/warnings.cmake)
87 include (${DYNINST_ROOT}/cmake/options.cmake)
88 include (${DYNINST_ROOT}/cmake/optimization.cmake)
89
90 set (BUILD_SHARED_LIBS ON)
91
92 set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries")
93 set (INSTALL_INCLUDE_DIR include CACHE PATH "Installation directory for header files")
94 set (INSTALL_CMAKE_DIR lib/cmake/${PROJECT_NAME} CACHE PATH "Installation directory for CMake files")
95 set (INSTALL_DOC_DIR doc CACHE PATH "Installation directory for manuals")
96
97 # Make the above absolute paths if necessary
98 foreach (p LIB INCLUDE CMAKE)
99   set (var INSTALL_${p}_DIR)
100   if (NOT IS_ABSOLUTE "${${var}}")
101      set (${var} "${CMAKE_INSTALL_PREFIX}/${${var}}")
102   endif()
103 endforeach()
104
105 if(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
106     add_definitions(-Dsnprintf=_snprintf)
107 endif()
108
109 #
110 # DyninstConfig.cmake
111
112 file (RELATIVE_PATH REL_INCLUDE_DIR "${INSTALL_CMAKE_DIR}" "${INSTALL_INCLUDE_DIR}")
113
114 # For the install tree
115 set (CONF_INCLUDE_DIRS "\${DYNINST_CMAKE_DIR}/${REL_INCLUDE_DIR}")
116
117 # set default configuration type
118
119 if (NOT CMAKE_BUILD_TYPE)
120    set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING 
121        "Choose the build type (None, Debug, Release, RelWithDebInfo, MinSizeRel)" FORCE)
122 endif()
123
124
125