1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
if(CMAKE_CL_64)
add_definitions(-D_64BITS)
endif()
# multi process compilation
add_compile_options(/MP)
set(TANGO_LIBRARY_NAME tango)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TANGO_LIBRARY_NAME ${TANGO_LIBRARY_NAME}d)
endif()
if(BUILD_SHARED_LIBS)
set_target_properties(tango PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
set(TANGO_LIBRARY_NAME ${TANGO_LIBRARY_NAME}-static)
endif()
message("Tango library is '${TANGO_LIBRARY_NAME}'")
#include and link directories
set(WIN32_LIBS "ws2_32.lib;mswsock.lib;advapi32.lib;comctl32.lib;odbc32.lib;")
set_target_properties(tango PROPERTIES
COMPILE_DEFINITIONS "${windows_defs}"
VERSION ${LIBRARY_VERSION}
SOVERSION ${SO_VERSION}
DEBUG_POSTFIX "d")
set_cflags_and_include(tango)
if(NOT BUILD_SHARED_LIBS)
set_target_properties(tango PROPERTIES
PREFIX "lib"
OUTPUT_NAME ${TANGO_LIBRARY_NAME})
endif()
# Always generate separate PDB files for shared builds, even for release build types
#
# https://docs.microsoft.com/en-us/cpp/build/reference/z7-zi-zi-debug-information-format
# https://docs.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info
target_compile_options(tango PRIVATE "/Zi")
target_link_libraries(tango
PRIVATE
${WIN32_LIBS})
set_property(TARGET tango PROPERTY LINK_FLAGS "/DEBUG")
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/Debug)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_BINARY_DIR}/Debug)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Debug)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Debug)
set(CMAKE_INSTALL_CONFIG_NAME Debug)
endif()
#install code
install(TARGETS tango
EXPORT TangoTargets
ARCHIVE DESTINATION lib COMPONENT static
RUNTIME DESTINATION bin COMPONENT dynamic)
install(DIRECTORY "$<TARGET_FILE_DIR:tango>/"
DESTINATION lib COMPONENT static
DESTINATION bin COMPONENT dynamic
FILES_MATCHING PATTERN "*.pdb")
# Install the header files for the target
function(tango_install_dependency_headers tgt)
if (NOT TARGET ${tgt})
return()
endif()
get_target_property(inc_dirs ${tgt} INTERFACE_INCLUDE_DIRECTORIES)
foreach(dir ${inc_dirs})
file(GLOB files "${dir}/*")
foreach (file ${files})
if (IS_DIRECTORY ${file})
install(DIRECTORY ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} FILES_MATCHING
REGEX ".*" REGEX "\\.in" EXCLUDE)
elseif(NOT ${file} MATCHES "\\.in$")
install(FILES ${file} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
endif()
endforeach()
endforeach()
endfunction()
# This will contain cmake code to recreate all the IMPORTED targets used
# by Tango
set(TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "")
# Install the lib/dll files for a target and add code to
# TANGO_INSTALL_DEPENDENCIES_IMPORTED_TARGETS to reconstitute the IMPORTED target
# once it has been installed.
function(tango_install_imported tgt)
get_target_property(type ${tgt} TYPE)
get_target_property(imported_cfgs ${tgt} IMPORTED_CONFIGURATIONS)
if (imported_cfgs)
foreach(cfg ${imported_cfgs})
string(TOUPPER ${cfg} cfg)
get_target_property(loc_${cfg} ${tgt} IMPORTED_LOCATION_${cfg})
get_target_property(implib_${cfg} ${tgt} IMPORTED_IMPLIB_${cfg})
get_filename_component(loc_name_${cfg} ${loc_${cfg}} NAME)
get_filename_component(implib_name_${cfg} ${implib_${cfg}} NAME)
endforeach()
list(GET imported_cfgs 0 fallback_cfg)
else()
set(fallback_cfg NONE)
endif()
if(${type} STREQUAL SHARED_LIBRARY)
set(LOCDIR ${CMAKE_INSTALL_BINDIR})
else()
set(LOCDIR ${CMAKE_INSTALL_LIBDIR})
endif()
foreach(cfg ${CMAKE_CONFIGURATION_TYPES})
string(TOUPPER ${cfg} cfg)
if (loc_${cfg})
install(FILES ${loc_${cfg}}
CONFIGURATIONS ${cfg}
DESTINATION ${LOCDIR}
)
elseif(loc_${fallback_cfg})
install(FILES ${loc_${fallback_cfg}}
CONFIGURATIONS ${cfg}
DESTINATION ${LOCDIR}
)
endif()
if (implib_${cfg})
install(FILES ${implib_${cfg}}
CONFIGURATIONS ${cfg}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
elseif(implib_${fallback_cfg})
install(FILES ${implib_${fallback_cfg}}
CONFIGURATIONS ${cfg}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()
endforeach()
if(${type} STREQUAL SHARED_LIBRARY)
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
add_library(${tgt} SHARED IMPORTED)\n")
elseif(${type} STREQUAL STATIC_LIBRARY)
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
add_library(${tgt} STATIC IMPORTED)\n")
else()
set(has_loc FALSE)
foreach(cfg ${imported_cfgs})
if (loc_${cfg})
set(has_loc TRUE)
endif()
endforeach()
if (has_loc)
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
add_library(${tgt} UNKNOWN IMPORTED)\n")
else()
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
add_library(${tgt} INTERFACE IMPORTED)\n")
endif()
endif()
# As we are installing all the include files to the same directory
# we do not need to copy an INTERFACE_INCLUDE_DIRECTORIES property
set(props_to_check
INTERFACE_LINK_LIBRARIES
INTERFACE_LINK_OPTIONS
STATIC_LIBRARY_OPTIONS
INTERFACE_COMPILE_FEATURES
INTERFACE_COMPILE_DEFINITIONS
INTERFACE_COMPILE_OPTIONS
)
set(props_copy_lines "")
foreach (prop ${props_to_check})
get_target_property(value ${tgt} ${prop})
if (value)
string(APPEND props_copy_lines " ${prop} \"${value}\"\n")
endif()
endforeach()
if (props_copy_lines)
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
set_target_properties(${tgt} PROPERTIES\n\
${props_copy_lines} )\n")
endif()
if (${type} STREQUAL SHARED_LIBRARY)
foreach(cfg ${imported_cfgs})
string(TOUPPER ${cfg} cfg)
if (loc_${cfg} AND implib_${cfg})
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
if(EXISTS \${TANGO_IMPORT_BINDIR}/${loc_name_${cfg}})\n\
set_property(TARGET ${tgt} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${cfg})\n\
set_target_properties(${tgt} PROPERTIES\n\
IMPORTED_LOCATION_${cfg} \${TANGO_IMPORT_BINDIR}/${loc_name_${cfg}}\n\
IMPORTED_IMPLIB_${cfg} \${TANGO_IMPORT_LIBDIR}/${implib_name_${cfg}}\n\
)\n\
endif()\n")
endif()
endforeach()
else()
foreach(cfg ${imported_cfgs})
string(TOUPPER ${cfg} cfg)
if (loc_${cfg})
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\
if(EXISTS \${TANGO_IMPORT_LIBDIR}/${loc_name_${cfg}})\n\
set_property(TARGET ${tgt} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${cfg})\n\
set_target_properties(${tgt} PROPERTIES\n\
IMPORTED_LOCATION_${cfg} \${TANGO_IMPORT_LIBDIR}/${loc_name_${cfg}}\n\
)\n\
endif()\n")
endif()
endforeach()
endif()
STRING(APPEND TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS "\n")
set(TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS ${TANGO_INSTALLED_DEPENDENCIES_IMPORTED_TARGETS} PARENT_SCOPE)
endfunction()
# Recursively look through INTERFACE_LINK_LIBRARIES targets of `tgt` and append
# them to the list `out` in the PARENT_SCOPE.
function(tango_gather_dependencies out tgt)
if (NOT TARGET ${tgt} OR ${tgt} IN_LIST ${out})
return()
endif()
list(APPEND ${out} ${tgt})
get_target_property(iface_link_libs ${tgt} INTERFACE_LINK_LIBRARIES)
if (iface_link_libs)
foreach (dep ${iface_link_libs})
string(REGEX REPLACE "\\\$<LINK_ONLY:(.*)>" "\\1" stripped ${dep})
tango_gather_dependencies(${out} ${stripped})
endforeach()
endif()
set(${out} ${${out}} PARENT_SCOPE)
endfunction()
if (TANGO_INSTALL_DEPENDENCIES)
# We want to install all the lib/dll files for _all_ the targets Tango::Tango depends on
get_target_property(TANGO_LINK_LIBS tango LINK_LIBRARIES)
foreach (tgt ${TANGO_LINK_LIBS})
tango_gather_dependencies(TANGO_LINK_DEPENDENCIES ${tgt})
endforeach()
foreach (tgt ${TANGO_LINK_DEPENDENCIES})
tango_install_imported(${tgt})
endforeach()
# We only want to install the include files for the INTERFACE_LIBRARIES
get_target_property(TANGO_IFACE_LIBS tango INTERFACE_LINK_LIBRARIES)
foreach (tgt ${TANGO_IFACE_LIBS})
tango_gather_dependencies(TANGO_HEADER_DEPENDENCIES ${tgt})
endforeach()
foreach(tgt ${TANGO_HEADER_DEPENDENCIES})
tango_install_dependency_headers(${tgt})
endforeach()
if(TANGO_USE_TELEMETRY)
if(BUILD_SHARED_LIBS)
message(FATAL_ERROR "Missing installation code")
else()
# This is a bit of hack because ZLIB::ZLIB is awkwardly defined as a UNKNOWN library
# and doesn't know about the DLL, so our logic above misses it.
# TODO: Somehow avoid this
if (NOT ZLIB_ROOT)
get_filename_component(ZLIB_LIBRARY_DIR ${ZLIB_LIBRARY} DIRECTORY)
get_filename_component(ZLIB_ROOT ${ZLIB_LIBRARY_DIR} DIRECTORY)
endif()
install(FILES ${ZLIB_ROOT}/bin/zlib1.dll DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
endif()
endif()
|