1############################################################################# 2# $Id: CMake.NCBIptb.install.cmake 618543 2020-10-21 19:11:32Z gouriano $ 3############################################################################# 4############################################################################# 5## 6## NCBI CMake wrapper extension 7## In NCBI CMake wrapper, adds installation commands 8## Author: Andrei Gourianov, gouriano@ncbi 9## 10 11 12############################################################################## 13function(NCBI_internal_install_target _variable _access) 14 if(NOT "${_access}" STREQUAL "MODIFIED_ACCESS") 15 return() 16 endif() 17 18 if (${NCBI_${NCBI_PROJECT}_TYPE} STREQUAL "STATIC") 19 set(_doexport YES) 20 set(_haspdb NO) 21 set(_dest ${NCBI_DIRNAME_PREBUILT}/${NCBI_DIRNAME_ARCHIVE}) 22 if(WIN32) 23 set_target_properties(${NCBI_PROJECT} PROPERTIES COMPILE_PDB_OUTPUT_DIRECTORY "${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}") 24 endif() 25 elseif (${NCBI_${NCBI_PROJECT}_TYPE} STREQUAL "SHARED") 26 set(_doexport YES) 27 set(_haspdb YES) 28 if (WIN32) 29 set(_dest ${NCBI_DIRNAME_PREBUILT}/${NCBI_DIRNAME_SHARED}) 30 set(_dest_ar ${NCBI_DIRNAME_PREBUILT}/${NCBI_DIRNAME_ARCHIVE}) 31 else() 32 set(_dest ${NCBI_DIRNAME_PREBUILT}/${NCBI_DIRNAME_ARCHIVE}) 33 endif() 34 elseif (${NCBI_${NCBI_PROJECT}_TYPE} STREQUAL "CONSOLEAPP" OR ${NCBI_${NCBI_PROJECT}_TYPE} STREQUAL "GUIAPP") 35 set(_doexport NO) 36 set(_haspdb YES) 37 set(_dest ${NCBI_DIRNAME_PREBUILT}/${NCBI_DIRNAME_RUNTIME}) 38 if (NOT "${NCBI_PTBCFG_INSTALL_TAGS}" STREQUAL "") 39 set(_alltags ${NCBI__PROJTAG} ${NCBI_${NCBI_PROJECT}_PROJTAG}) 40 set(_res FALSE) 41 set(_hasp FALSE) 42 foreach(_tag IN LISTS NCBI_PTBCFG_INSTALL_TAGS) 43 NCBI_util_parse_sign( ${_tag} _value _negate) 44 if(_negate) 45 if( ${_value} IN_LIST _alltags) 46 if(NCBI_VERBOSE_ALLPROJECTS OR NCBI_VERBOSE_PROJECT_${NCBI_PROJECT}) 47 message("${NCBI_PROJECT} will not be installed because of tag ${_value}") 48 endif() 49 return() 50 endif() 51 else() 52 set(_hasp TRUE) 53 if( ${_value} IN_LIST _alltags OR ${_value} STREQUAL "*") 54 set(_res TRUE) 55 endif() 56 endif() 57 endforeach() 58 if(_hasp AND NOT _res) 59 if(NCBI_VERBOSE_ALLPROJECTS OR NCBI_VERBOSE_PROJECT_${NCBI_PROJECT}) 60 message("${NCBI_PROJECT} will not be installed because of tags ${_alltags}") 61 endif() 62 return() 63 endif() 64 endif() 65 if(${NCBI_PROJECT} MATCHES "test|demo|sample") 66 if(NCBI_VERBOSE_ALLPROJECTS OR NCBI_VERBOSE_PROJECT_${NCBI_PROJECT}) 67 message("${NCBI_PROJECT} will not be installed because of its name") 68 endif() 69 return() 70 endif() 71 else() 72 return() 73 endif() 74 if ("${_dest}" STREQUAL "") 75 return() 76 endif() 77 78# not sure about this part 79 file(RELATIVE_PATH _rel "${NCBI_SRC_ROOT}" "${NCBI_CURRENT_SOURCE_DIR}") 80 string(REPLACE "/" ";" _rel ${_rel}) 81 list(GET _rel 0 _dir) 82 get_property(_all_subdirs GLOBAL PROPERTY NCBI_PTBPROP_ROOT_SUBDIR) 83 list(APPEND _all_subdirs ${_dir}) 84 if (DEFINED NCBI_${NCBI_PROJECT}_PARTS) 85 foreach(_rel IN LISTS NCBI_${NCBI_PROJECT}_PARTS) 86 string(REPLACE "/" ";" _rel ${_rel}) 87 list(GET _rel 0 _dir) 88 list(APPEND _all_subdirs ${_dir}) 89 endforeach() 90 endif() 91 list(REMOVE_DUPLICATES _all_subdirs) 92 set_property(GLOBAL PROPERTY NCBI_PTBPROP_ROOT_SUBDIR ${_all_subdirs}) 93 94 file(RELATIVE_PATH _rel "${NCBI_SRC_ROOT}" "${NCBI_CURRENT_SOURCE_DIR}") 95 get_property(_all_subdirs GLOBAL PROPERTY NCBI_PTBPROP_SOURCE_DIR) 96 list(APPEND _all_subdirs ${_rel}) 97 if (DEFINED NCBI_${NCBI_PROJECT}_PARTS) 98 foreach(_rel IN LISTS NCBI_${NCBI_PROJECT}_PARTS) 99 list(APPEND _all_subdirs ${_rel}) 100 endforeach() 101 endif() 102 list(SORT _all_subdirs) 103 list(REMOVE_DUPLICATES _all_subdirs) 104 set_property(GLOBAL PROPERTY NCBI_PTBPROP_SOURCE_DIR ${_all_subdirs}) 105 106 NCBI_util_get_value(PROPERTY_EXPORT _entry) 107 if (NOT "${_entry}" STREQUAL "") 108 set(_doexport ${_entry}) 109 endif() 110 set(_exp "") 111 if (WIN32 OR XCODE) 112 foreach(_cfg IN LISTS NCBI_CONFIGURATION_TYPES) 113 if(_doexport) 114 set(_exp EXPORT ${NCBI_PTBCFG_INSTALL_EXPORT}${_cfg}) 115 endif() 116 if (DEFINED _dest_ar) 117 install( 118 TARGETS ${NCBI_PROJECT} 119 ${_exp} 120 RUNTIME DESTINATION ${_dest}/${_cfg} 121 CONFIGURATIONS ${_cfg} 122 ARCHIVE DESTINATION ${_dest_ar}/${_cfg} 123 CONFIGURATIONS ${_cfg} 124 ) 125 else() 126 install( 127 TARGETS ${NCBI_PROJECT} 128 ${_exp} 129 DESTINATION ${_dest}/${_cfg} 130 CONFIGURATIONS ${_cfg} 131 ) 132 endif() 133 if (WIN32) 134 if (_haspdb) 135 install(FILES $<TARGET_PDB_FILE:${NCBI_PROJECT}> 136 DESTINATION ${_dest}/${_cfg} OPTIONAL 137 CONFIGURATIONS ${_cfg}) 138 else() 139 install(FILES $<TARGET_FILE:${NCBI_PROJECT}>.pdb 140 DESTINATION ${_dest}/${_cfg} OPTIONAL 141 CONFIGURATIONS ${_cfg}) 142 endif() 143 endif() 144 endforeach() 145 else() 146 if(_doexport) 147 set(_exp EXPORT ${NCBI_PTBCFG_INSTALL_EXPORT}) 148 endif() 149 install( 150 TARGETS ${NCBI_PROJECT} 151 ${_exp} 152 DESTINATION ${_dest} 153 ) 154 endif() 155endfunction() 156 157############################################################################## 158function(NCBI_internal_export_hostinfo _file) 159 if(EXISTS ${_file}) 160 file(REMOVE ${_file}) 161 endif() 162 get_property(_allprojects GLOBAL PROPERTY NCBI_PTBPROP_ALL_PROJECTS) 163 if (NOT "${_allprojects}" STREQUAL "") 164 set(_hostinfo) 165 foreach(_prj IN LISTS _allprojects) 166 get_property(_prjhost GLOBAL PROPERTY NCBI_PTBPROP_HOST_${_prj}) 167 if (NOT "${_prjhost}" STREQUAL "") 168 list(APPEND _hostinfo "${_prj} ${_prjhost}\n") 169 endif() 170 endforeach() 171 if (NOT "${_hostinfo}" STREQUAL "") 172 file(WRITE ${_file} ${_hostinfo}) 173 endif() 174 endif() 175endfunction() 176 177############################################################################## 178function(NCBI_internal_export_buildinfo _file) 179 if(EXISTS ${_file}) 180 file(REMOVE ${_file}) 181 endif() 182 set(_buildinfo) 183 if (MSVC) 184 list(APPEND _buildinfo "set CMAKE_GENERATOR=${CMAKE_GENERATOR}\n") 185 list(APPEND _buildinfo "set BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}\n") 186 elseif(XCODE) 187 list(APPEND _buildinfo "CMAKE_GENERATOR=\"${CMAKE_GENERATOR}\"\n") 188 list(APPEND _buildinfo "BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}\n") 189 else() 190 list(APPEND _buildinfo "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}\n") 191 list(APPEND _buildinfo "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}\n") 192 list(APPEND _buildinfo "CMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}\n") 193 list(APPEND _buildinfo "BUILD_SHARED_LIBS=${BUILD_SHARED_LIBS}\n") 194 endif() 195 file(WRITE ${_file} ${_buildinfo}) 196endfunction() 197 198############################################################################## 199function(NCBI_internal_install_root _variable _access) 200 if(NOT "${_access}" STREQUAL "MODIFIED_ACCESS") 201 return() 202 endif() 203 204 set(_dest ${NCBI_DIRNAME_PREBUILT}) 205 set(_hostinfo ${NCBI_BUILD_ROOT}/${NCBI_DIRNAME_BUILD}/${CMAKE_PROJECT_NAME}.hostinfo) 206 NCBI_internal_export_hostinfo(${_hostinfo}) 207 if (EXISTS ${_hostinfo}) 208 install( FILES ${_hostinfo} DESTINATION ${_dest}/${NCBI_DIRNAME_EXPORT} RENAME ${NCBI_PTBCFG_INSTALL_EXPORT}.hostinfo) 209 endif() 210 211 set(_buildinfo ${NCBI_BUILD_ROOT}/${NCBI_DIRNAME_BUILD}/${CMAKE_PROJECT_NAME}.buildinfo) 212 NCBI_internal_export_buildinfo(${_buildinfo}) 213 if (EXISTS ${_buildinfo}) 214 install( FILES ${_buildinfo} DESTINATION ${_dest}/${NCBI_DIRNAME_EXPORT} RENAME buildinfo) 215 endif() 216 217 if (WIN32 OR XCODE) 218 foreach(_cfg IN LISTS NCBI_CONFIGURATION_TYPES) 219 install(EXPORT ${NCBI_PTBCFG_INSTALL_EXPORT}${_cfg} 220 CONFIGURATIONS ${_cfg} 221 DESTINATION ${_dest}/${NCBI_DIRNAME_EXPORT} 222 FILE ${NCBI_PTBCFG_INSTALL_EXPORT}.cmake 223 ) 224 endforeach() 225 else() 226 install(EXPORT ${NCBI_PTBCFG_INSTALL_EXPORT} 227 DESTINATION ${_dest}/${NCBI_DIRNAME_EXPORT} 228 FILE ${NCBI_PTBCFG_INSTALL_EXPORT}.cmake 229 ) 230 endif() 231 232# install headers 233 get_property(_all_subdirs GLOBAL PROPERTY NCBI_PTBPROP_ROOT_SUBDIR) 234 list(APPEND _all_subdirs ${NCBI_DIRNAME_COMMON_INCLUDE}) 235 foreach(_dir IN LISTS _all_subdirs) 236 if (EXISTS ${NCBI_INC_ROOT}/${_dir}) 237 install( DIRECTORY ${NCBI_INC_ROOT}/${_dir} DESTINATION ${NCBI_DIRNAME_INCLUDE} 238 REGEX "/[.].*$" EXCLUDE) 239 endif() 240 endforeach() 241 file(GLOB _files LIST_DIRECTORIES false "${NCBI_INC_ROOT}/*") 242 install( FILES ${_files} DESTINATION ${NCBI_DIRNAME_INCLUDE}) 243 244# install sources 245 if ($ENV{NCBIPTB_INSTALL_SRC}) 246 get_property(_all_subdirs GLOBAL PROPERTY PROPERTY NCBI_PTBPROP_SOURCE_DIR) 247 foreach(_dir IN LISTS _all_subdirs) 248 if (EXISTS ${NCBI_SRC_ROOT}/${_dir}) 249 get_filename_component(_path ${_dir} DIRECTORY) 250 if(NOT "${_path}" STREQUAL "") 251 set(_path "/${_path}") 252 endif() 253 install( DIRECTORY ${NCBI_SRC_ROOT}/${_dir} DESTINATION ${NCBI_DIRNAME_SRC}${_path} 254 FILES_MATCHING PATTERN "*.c" PATTERN "*.c??" REGEX "/[.].*$" EXCLUDE REGEX "${NCBI_SRC_ROOT}/${_dir}/.*/[^/]" EXCLUDE) 255 endif() 256 endforeach() 257 file(GLOB _files LIST_DIRECTORIES false "${NCBI_SRC_ROOT}/*") 258 install( FILES ${_files} DESTINATION ${NCBI_DIRNAME_SRC}) 259 endif() 260 261 file(GLOB _files LIST_DIRECTORIES false "${NCBI_TREE_BUILDCFG}/*") 262 install( FILES ${_files} DESTINATION ${NCBI_DIRNAME_BUILDCFG}) 263 install( DIRECTORY ${NCBI_TREE_CMAKECFG} DESTINATION ${NCBI_DIRNAME_BUILDCFG} 264 USE_SOURCE_PERMISSIONS REGEX "/[.].*$" EXCLUDE) 265 266 install( DIRECTORY ${NCBI_TREE_ROOT}/${NCBI_DIRNAME_SCRIPTS} DESTINATION "." 267 USE_SOURCE_PERMISSIONS REGEX "/[.].*$" EXCLUDE) 268 269 install( DIRECTORY ${NCBI_CFGINC_ROOT} DESTINATION "${_dest}" 270 REGEX "/[.].*$" EXCLUDE) 271 272# test results 273 if ($ENV{NCBIPTB_INSTALL_CHECK}) 274 install( DIRECTORY ${NCBI_BUILD_ROOT}/check DESTINATION "${_dest}") 275 install( DIRECTORY ${NCBI_BUILD_ROOT}/testing DESTINATION "${_dest}") 276 else() 277 if (WIN32 OR XCODE) 278 install( DIRECTORY ${NCBI_BUILD_ROOT}/check DESTINATION "${_dest}" 279 REGEX "${NCBI_BUILD_ROOT}/check/.*/.*/[^/]" EXCLUDE 280 ) 281# install( DIRECTORY ${NCBI_BUILD_ROOT}/testing DESTINATION "${_dest}" 282# REGEX "${NCBI_BUILD_ROOT}/testing/.*/.*/[^/]" EXCLUDE 283# ) 284 else() 285 install( DIRECTORY ${NCBI_BUILD_ROOT}/check DESTINATION "${_dest}" 286 REGEX "${NCBI_BUILD_ROOT}/check/.*/[^/]" EXCLUDE 287 ) 288# install( DIRECTORY ${NCBI_BUILD_ROOT}/testing DESTINATION "${_dest}" 289# REGEX "${NCBI_BUILD_ROOT}/testing/.*/[^/]" EXCLUDE 290# ) 291 endif() 292 endif() 293 if (WIN32 OR XCODE) 294 install( DIRECTORY ${NCBI_BUILD_ROOT}/${NCBI_DIRNAME_BUILD}/Testing/Temporary/ DESTINATION "${_dest}/testing/$<CONFIG>") 295 else() 296 install( DIRECTORY ${NCBI_BUILD_ROOT}/${NCBI_DIRNAME_BUILD}/Testing/Temporary/ DESTINATION "${_dest}/testing") 297 endif() 298 299#install build info files 300 set(_files "${NCBI_TREE_ROOT}/build_info;${NCBI_TREE_ROOT}/checkout_info") 301 install(FILES ${_files} DESTINATION "." OPTIONAL) 302endfunction() 303 304############################################################################# 305if (NOT "${NCBI_PTBCFG_INSTALL_PATH}" STREQUAL "") 306 string(REPLACE "\\" "/" NCBI_PTBCFG_INSTALL_PATH ${NCBI_PTBCFG_INSTALL_PATH}) 307 set(CMAKE_INSTALL_PREFIX "${NCBI_PTBCFG_INSTALL_PATH}" CACHE STRING "Reset the installation destination" FORCE) 308endif() 309set(CMAKE_SUPPRESS_REGENERATION ON) 310set(NCBI_PTBCFG_INSTALL_TAGS "*;-test;-demo;-sample") 311NCBI_register_hook(TARGET_ADDED NCBI_internal_install_target) 312NCBI_register_hook(ALL_ADDED NCBI_internal_install_root) 313