From 94b0cde8c541aaa313ccf470d260159c4dd132cb Mon Sep 17 00:00:00 2001 From: Tossy0423 Date: Sun, 19 Sep 2021 17:21:53 +0900 Subject: [PATCH] Merged from AlexeyAB/darknet --- build/darknet/x64/darknet_video.py | 81 ++++++-- build/darknet/x64/partial.cmd | 9 + cmake/Modules/FindCUDNN.cmake | 68 ++++--- cmake/Modules/FindPThreads4W.cmake | 229 +++++++++++++++++++++++ cmake/Modules/FindPThreads_windows.cmake | 83 -------- 5 files changed, 345 insertions(+), 125 deletions(-) create mode 100644 cmake/Modules/FindPThreads4W.cmake delete mode 100644 cmake/Modules/FindPThreads_windows.cmake diff --git a/build/darknet/x64/darknet_video.py b/build/darknet/x64/darknet_video.py index de96d709ed1..5e7036203a7 100644 --- a/build/darknet/x64/darknet_video.py +++ b/build/darknet/x64/darknet_video.py @@ -60,17 +60,63 @@ def set_saved_video(input_video, output_video, size): return video +def convert2relative(bbox): + """ + YOLO format use relative coordinates for annotation + """ + x, y, w, h = bbox + _height = darknet_height + _width = darknet_width + return x/_width, y/_height, w/_width, h/_height + + +def convert2original(image, bbox): + x, y, w, h = convert2relative(bbox) + + image_h, image_w, __ = image.shape + + orig_x = int(x * image_w) + orig_y = int(y * image_h) + orig_width = int(w * image_w) + orig_height = int(h * image_h) + + bbox_converted = (orig_x, orig_y, orig_width, orig_height) + + return bbox_converted + + +def convert4cropping(image, bbox): + x, y, w, h = convert2relative(bbox) + + image_h, image_w, __ = image.shape + + orig_left = int((x - w / 2.) * image_w) + orig_right = int((x + w / 2.) * image_w) + orig_top = int((y - h / 2.) * image_h) + orig_bottom = int((y + h / 2.) * image_h) + + if (orig_left < 0): orig_left = 0 + if (orig_right > image_w - 1): orig_right = image_w - 1 + if (orig_top < 0): orig_top = 0 + if (orig_bottom > image_h - 1): orig_bottom = image_h - 1 + + bbox_cropping = (orig_left, orig_top, orig_right, orig_bottom) + + return bbox_cropping + + def video_capture(frame_queue, darknet_image_queue): while cap.isOpened(): ret, frame = cap.read() if not ret: break frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) - frame_resized = cv2.resize(frame_rgb, (width, height), + frame_resized = cv2.resize(frame_rgb, (darknet_width, darknet_height), interpolation=cv2.INTER_LINEAR) - frame_queue.put(frame_resized) - darknet.copy_image_from_bytes(darknet_image, frame_resized.tobytes()) - darknet_image_queue.put(darknet_image) + frame_queue.put(frame) + img_for_detect = darknet.make_image(darknet_width, darknet_height, 3) + darknet.copy_image_from_bytes(img_for_detect, frame_resized.tobytes()) + darknet_image_queue.put(img_for_detect) cap.release() @@ -84,23 +130,27 @@ def inference(darknet_image_queue, detections_queue, fps_queue): fps_queue.put(fps) print("FPS: {}".format(fps)) darknet.print_detections(detections, args.ext_output) + darknet.free_image(darknet_image) cap.release() def drawing(frame_queue, detections_queue, fps_queue): random.seed(3) # deterministic bbox colors - video = set_saved_video(cap, args.out_filename, (width, height)) + video = set_saved_video(cap, args.out_filename, (video_width, video_height)) while cap.isOpened(): - frame_resized = frame_queue.get() + frame = frame_queue.get() detections = detections_queue.get() fps = fps_queue.get() - if frame_resized is not None: - image = darknet.draw_boxes(detections, frame_resized, class_colors) - image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) - if args.out_filename is not None: - video.write(image) + detections_adjusted = [] + if frame is not None: + for label, confidence, bbox in detections: + bbox_adjusted = convert2original(frame, bbox) + detections_adjusted.append((str(label), confidence, bbox_adjusted)) + image = darknet.draw_boxes(detections_adjusted, frame, class_colors) if not args.dont_show: cv2.imshow('Inference', image) + if args.out_filename is not None: + video.write(image) if cv2.waitKey(fps) == 27: break cap.release() @@ -122,13 +172,12 @@ def drawing(frame_queue, detections_queue, fps_queue): args.weights, batch_size=1 ) - # Darknet doesn't accept numpy images. - # Create one with image we reuse for each detect - width = darknet.network_width(network) - height = darknet.network_height(network) - darknet_image = darknet.make_image(width, height, 3) + darknet_width = darknet.network_width(network) + darknet_height = darknet.network_height(network) input_path = str2int(args.input) cap = cv2.VideoCapture(input_path) + video_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH)) + video_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)) Thread(target=video_capture, args=(frame_queue, darknet_image_queue)).start() Thread(target=inference, args=(darknet_image_queue, detections_queue, fps_queue)).start() Thread(target=drawing, args=(frame_queue, detections_queue, fps_queue)).start() diff --git a/build/darknet/x64/partial.cmd b/build/darknet/x64/partial.cmd index 6080cf68b89..ee0cb0d2437 100644 --- a/build/darknet/x64/partial.cmd +++ b/build/darknet/x64/partial.cmd @@ -2,6 +2,15 @@ rem Download weights for - DenseNet201, ResNet50 and ResNet152 by this link: htt rem Download Yolo/Tiny-yolo: https://pjreddie.com/darknet/yolo/ rem Download Yolo9000: http://pjreddie.com/media/files/yolo9000.weights + +darknet.exe partial cfg/yolov4-csp-swish.cfg yolov4-csp-swish.weights yolov4-csp-swish.conv.164 164 + + +darknet.exe partial cfg/yolov4-csp-x-swish.cfg yolov4-csp-x-swish.weights yolov4-csp-x-swish.conv.192 192 + + +pause + darknet.exe partial cfg/yolov4-csp.cfg yolov4-csp.weights yolov4-csp.conv.142 142 darknet.exe partial cfg/yolov4x-mish.cfg yolov4x-mish.weights yolov4x-mish.conv.166 166 diff --git a/cmake/Modules/FindCUDNN.cmake b/cmake/Modules/FindCUDNN.cmake index 871295faaee..7a692b055d5 100644 --- a/cmake/Modules/FindCUDNN.cmake +++ b/cmake/Modules/FindCUDNN.cmake @@ -19,39 +19,55 @@ # ``CUDNN_LIBRARIES`` # The CUDNN libraries. # +# ``CuDNN::CuDNN`` +# The CUDNN target +# include(FindPackageHandleStandardArgs) -if(NOT CUDNN_INCLUDE_DIR) - find_path(CUDNN_INCLUDE_DIR cudnn.h - HINTS ${CUDA_HOME} ${CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN} - PATH_SUFFIXES cuda/include include) -endif() - -if(NOT CUDNN_LIBRARY) - find_library(CUDNN_LIBRARY cudnn - HINTS ${CUDA_HOME} ${CUDA_TOOLKIT_ROOT_DIR} $ENV{cudnn} $ENV{CUDNN} - PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64) -endif() - +find_path(CUDNN_INCLUDE_DIR NAMES cudnn.h cudnn_v8.h cudnn_v7.h + HINTS $ENV{CUDA_PATH} $ENV{CUDA_TOOLKIT_ROOT_DIR} $ENV{CUDA_HOME} $ENV{CUDNN_ROOT_DIR} /usr/include + PATH_SUFFIXES cuda/include include) +find_library(CUDNN_LIBRARY NAMES cudnn cudnn8 cudnn7 + HINTS $ENV{CUDA_PATH} $ENV{CUDA_TOOLKIT_ROOT_DIR} $ENV{CUDA_HOME} $ENV{CUDNN_ROOT_DIR} /usr/lib/x86_64-linux-gnu/ + PATH_SUFFIXES lib lib64 cuda/lib cuda/lib64 lib/x64 cuda/lib/x64) if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn.h") file(READ ${CUDNN_INCLUDE_DIR}/cudnn.h CUDNN_HEADER_CONTENTS) - string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" - CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}") - string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1" - CUDNN_VERSION_MAJOR "${CUDNN_VERSION_MAJOR}") - string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)" - CUDNN_VERSION_MINOR "${CUDNN_HEADER_CONTENTS}") - string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1" - CUDNN_VERSION_MINOR "${CUDNN_VERSION_MINOR}") - string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)" - CUDNN_VERSION_PATCH "${CUDNN_HEADER_CONTENTS}") - string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1" - CUDNN_VERSION_PATCH "${CUDNN_VERSION_PATCH}") - if(NOT CUDNN_VERSION_MAJOR) +elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_v8.h") + file(READ ${CUDNN_INCLUDE_DIR}/cudnn_v8.h CUDNN_HEADER_CONTENTS) +elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_v7.h") + file(READ ${CUDNN_INCLUDE_DIR}/cudnn_v7.h CUDNN_HEADER_CONTENTS) +endif() +if(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version.h") + file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version.h" CUDNN_VERSION_H_CONTENTS) + string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}") + unset(CUDNN_VERSION_H_CONTENTS) +elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version_v8.h") + file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version_v8.h" CUDNN_VERSION_H_CONTENTS) + string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}") + unset(CUDNN_VERSION_H_CONTENTS) +elseif(EXISTS "${CUDNN_INCLUDE_DIR}/cudnn_version_v7.h") + file(READ "${CUDNN_INCLUDE_DIR}/cudnn_version_v7.h" CUDNN_VERSION_H_CONTENTS) + string(APPEND CUDNN_HEADER_CONTENTS "${CUDNN_VERSION_H_CONTENTS}") + unset(CUDNN_VERSION_H_CONTENTS) +endif() +if(CUDNN_HEADER_CONTENTS) + string(REGEX MATCH "define CUDNN_MAJOR * +([0-9]+)" + _CUDNN_VERSION_MAJOR "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_MAJOR * +([0-9]+)" "\\1" + _CUDNN_VERSION_MAJOR "${_CUDNN_VERSION_MAJOR}") + string(REGEX MATCH "define CUDNN_MINOR * +([0-9]+)" + _CUDNN_VERSION_MINOR "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_MINOR * +([0-9]+)" "\\1" + _CUDNN_VERSION_MINOR "${_CUDNN_VERSION_MINOR}") + string(REGEX MATCH "define CUDNN_PATCHLEVEL * +([0-9]+)" + _CUDNN_VERSION_PATCH "${CUDNN_HEADER_CONTENTS}") + string(REGEX REPLACE "define CUDNN_PATCHLEVEL * +([0-9]+)" "\\1" + _CUDNN_VERSION_PATCH "${_CUDNN_VERSION_PATCH}") + if(NOT _CUDNN_VERSION_MAJOR) set(CUDNN_VERSION "?") else() - set(CUDNN_VERSION "${CUDNN_VERSION_MAJOR}.${CUDNN_VERSION_MINOR}.${CUDNN_VERSION_PATCH}") + set(CUDNN_VERSION "${_CUDNN_VERSION_MAJOR}.${_CUDNN_VERSION_MINOR}.${_CUDNN_VERSION_PATCH}") endif() endif() diff --git a/cmake/Modules/FindPThreads4W.cmake b/cmake/Modules/FindPThreads4W.cmake new file mode 100644 index 00000000000..18e2b77c814 --- /dev/null +++ b/cmake/Modules/FindPThreads4W.cmake @@ -0,0 +1,229 @@ +# Distributed under the OSI-approved BSD 3-Clause License. +# Copyright Stefano Sinigardi + +#.rst: +# FindPThreads4W +# ------------ +# +# Find the PThread4W includes and library. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This script defines the following variables: +# +# ``PThreads4W_FOUND`` +# True if PThreads4W library found +# +# ``PThreads4W_VERSION`` +# Containing the PThreads4W version tag (manually defined) +# +# ``PThreads4W_INCLUDE_DIR`` +# Location of PThreads4W headers +# +# ``PThreads4W_LIBRARY`` +# List of libraries to link with when using PThreads4W (no exception handling) +# +# ``PThreads4W_CXXEXC_LIBRARY`` +# List of libraries to link with when using PThreads4W (C++ exception handling) +# +# ``PThreads4W_STRUCTEXC_LIBRARY`` +# List of libraries to link with when using PThreads4W (struct exception handling) +# +# Result Targets +# ^^^^^^^^^^^^^^^^ +# +# This script defines the following targets: +# +# ``PThreads4W::PThreads4W`` +# Target to use PThreads4W (no exception handling) +# +# ``PThreads4W::PThreads4W_CXXEXC`` +# Target to use PThreads4W (C++ exception handling) +# +# ``PThreads4W::PThreads4W_STRUCTEXC`` +# Target to use PThreads4W (struct exception handling) +# + +include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) +include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake) + +if(NOT PThreads4W_INCLUDE_DIR) + find_path(PThreads4W_INCLUDE_DIR NAMES pthread.h) +endif() + +set(PThreads4W_MAJOR_VERSION 2) +set(PThreads4W_MINOR_VERSION 0) +set(PThreads4W_PATCH_VERSION 0) +set(PThreads4W_VERSION "${PThreads4W_MAJOR_VERSION}.${PThreads4W_MINOR_VERSION}.${PThreads4W_PATCH_VERSION}") + +# Allow libraries to be set manually +if(NOT PThreads4W_LIBRARY) + find_library(PThreads4W_LIBRARY NAMES pthreadVC${PThreads4W_MAJOR_VERSION}) + find_library(PThreads4W_LIBRARY_RELEASE NAMES pthreadVC${PThreads4W_MAJOR_VERSION}) +endif() +if(NOT PThreads4W_CXXEXC_LIBRARY) + find_library(PThreads4W_CXXEXC_LIBRARY_RELEASE NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}) + find_library(PThreads4W_CXXEXC_LIBRARY_DEBUG NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}d) + select_library_configurations(PThreads4W_CXXEXC) +endif() +if(NOT PThreads4W_STRUCTEXC_LIBRARY) + find_library(PThreads4W_STRUCTEXC_LIBRARY_RELEASE NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}) + find_library(PThreads4W_STRUCTEXC_LIBRARY_DEBUG NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}d) + select_library_configurations(PThreads4W_STRUCTEXC) +endif() + +find_package_handle_standard_args(PThreads4W DEFAULT_MSG PThreads4W_LIBRARY PThreads4W_INCLUDE_DIR) +mark_as_advanced(PThreads4W_INCLUDE_DIR PThreads4W_LIBRARY) + +set(PThreads4W_DLL_DIR ${PThreads4W_INCLUDE_DIR}) +list(TRANSFORM PThreads4W_DLL_DIR APPEND "/../bin") +message(STATUS "PThreads4W_DLL_DIR: ${PThreads4W_DLL_DIR}") +set(PThreads4W_DEBUG_DLL_DIR ${PThreads4W_INCLUDE_DIR}) +list(TRANSFORM PThreads4W_DEBUG_DLL_DIR APPEND "/../debug/bin") +message(STATUS "PThreads4W_DEBUG_DLL_DIR: ${PThreads4W_DEBUG_DLL_DIR}") + +find_file(PThreads4W_LIBRARY_RELEASE_DLL NAMES pthreadVC${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) +find_file(PThreads4W_LIBRARY_DEBUG_DLL NAMES pthreadVC${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) +find_file(PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) +find_file(PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL NAMES pthreadVCE${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) +find_file(PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}.dll PATHS ${PThreads4W_DLL_DIR}) +find_file(PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL NAMES pthreadVSE${PThreads4W_MAJOR_VERSION}d.dll PATHS ${PThreads4W_DEBUG_DLL_DIR}) + +#Compatibility definitions, deprecated +set(PTHREAD_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") +set(PTHREADS_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") +set(PThreads_windows_INCLUDE_DIR ${PThreads4W_INCLUDE_DIR} CACHE PATH "") +set(PTHREAD_LIBRARIES ${PThreads4W_LIBRARY} CACHE STRING "") +set(PTHREADS_LIBRARIES ${PThreads4W_LIBRARY} CACHE STRING "") +set(PTHREAD_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") +set(PTHREADS_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") +set(LIBPTHREAD ${PThreads4W_LIBRARY} CACHE STRING "") +set(LIBPTHREADS ${PThreads4W_LIBRARY} CACHE STRING "") +set(PThreads_windows_LIBRARY ${PThreads4W_LIBRARY} CACHE STRING "") +set(PThreads_VERSION "${PThreads4W_VERSION}") +if(PThreads4W_FOUND) + set(PThreads_windows_FOUND TRUE) +endif() + +#TARGETS +if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W_CXXEXC ) + if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL}" ) + add_library( PThreads4W::PThreads4W_CXXEXC SHARED IMPORTED ) + set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_CXXEXC_LIBRARY_RELEASE_DLL}" + IMPORTED_IMPLIB "${PThreads4W_CXXEXC_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL}" ) + set_property( TARGET PThreads4W::PThreads4W_CXXEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG_DLL}" + IMPORTED_IMPLIB_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) + endif() + else() + add_library( PThreads4W::PThreads4W_CXXEXC UNKNOWN IMPORTED ) + set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_CXXEXC_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) + set_property( TARGET PThreads4W::PThreads4W_CXXEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W_CXXEXC PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_CXXEXC_LIBRARY_DEBUG}" ) + endif() + endif() +endif() + +if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W_STRUCTEXC ) + if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL}" ) + add_library( PThreads4W::PThreads4W_STRUCTEXC SHARED IMPORTED ) + set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE_DLL}" + IMPORTED_IMPLIB "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL}" ) + set_property( TARGET PThreads4W::PThreads4W_STRUCTEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG_DLL}" + IMPORTED_IMPLIB_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) + endif() + else() + add_library( PThreads4W::PThreads4W_STRUCTEXC UNKNOWN IMPORTED ) + set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_STRUCTEXC_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) + set_property( TARGET PThreads4W::PThreads4W_STRUCTEXC APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W_STRUCTEXC PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_STRUCTEXC_LIBRARY_DEBUG}" ) + endif() + endif() +endif() + +if( PThreads4W_FOUND AND NOT TARGET PThreads4W::PThreads4W ) + if( EXISTS "${PThreads4W_LIBRARY_RELEASE_DLL}" ) + add_library( PThreads4W::PThreads4W SHARED IMPORTED ) + set_target_properties( PThreads4W::PThreads4W PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE_DLL}" + IMPORTED_IMPLIB "${PThreads4W_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_LIBRARY_DEBUG_DLL}" ) + set_property( TARGET PThreads4W::PThreads4W APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG_DLL}" + IMPORTED_IMPLIB_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) + endif() + else() + add_library( PThreads4W::PThreads4W UNKNOWN IMPORTED ) + set_target_properties( PThreads4W::PThreads4W PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_LIBRARY_DEBUG}" ) + set_property( TARGET PThreads4W::PThreads4W APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads4W::PThreads4W PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) + endif() + endif() +endif() + +#Compatibility targets, deprecated +if( PThreads4W_FOUND AND NOT TARGET PThreads_windows::PThreads_windows ) + if( EXISTS "${PThreads4W_LIBRARY_RELEASE_DLL}" ) + add_library( PThreads_windows::PThreads_windows SHARED IMPORTED ) + set_target_properties( PThreads_windows::PThreads_windows PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE_DLL}" + IMPORTED_IMPLIB "${PThreads4W_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_LIBRARY_DEBUG_DLL}" ) + set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads_windows::PThreads_windows PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG_DLL}" + IMPORTED_IMPLIB_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) + endif() + else() + add_library( PThreads_windows::PThreads_windows UNKNOWN IMPORTED ) + set_target_properties( PThreads_windows::PThreads_windows PROPERTIES + IMPORTED_LOCATION_RELEASE "${PThreads4W_LIBRARY_RELEASE}" + INTERFACE_INCLUDE_DIRECTORIES "${PThreads4W_INCLUDE_DIR}" + IMPORTED_CONFIGURATIONS Release + IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) + if( EXISTS "${PThreads4W_LIBRARY_DEBUG}" ) + set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) + set_target_properties( PThreads_windows::PThreads_windows PROPERTIES + IMPORTED_LOCATION_DEBUG "${PThreads4W_LIBRARY_DEBUG}" ) + endif() + endif() +endif() diff --git a/cmake/Modules/FindPThreads_windows.cmake b/cmake/Modules/FindPThreads_windows.cmake deleted file mode 100644 index 64e314005ff..00000000000 --- a/cmake/Modules/FindPThreads_windows.cmake +++ /dev/null @@ -1,83 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. -# Copyright Stefano Sinigardi - -#.rst: -# FindPThreads -# ------------ -# -# Find the PThreads includes and library. -# -# Result Variables -# ^^^^^^^^^^^^^^^^ -# -# This module defines the following variables: -# -# ``PThreads_windows_FOUND`` -# True if PThreads_windows library found -# -# ``PThreads_windows_INCLUDE_DIR`` -# Location of PThreads_windows headers -# -# ``PThreads_windows_LIBRARY`` -# List of libraries to link with when using PThreads_windows -# - -include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) -include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake) - -if(NOT PThreads_windows_INCLUDE_DIR) - find_path(PThreads_windows_INCLUDE_DIR NAMES pthread.h PATHS ${PThreads_windows_DIR} PATH_SUFFIXES include) -endif() - -# Allow libraries to be set manually -if(NOT PThreads_windows_LIBRARY) - find_library(PThreads_windows_LIBRARY_RELEASE NAMES pthreadsVC2 pthreadVC2 PATHS ${PThreads_windows_DIR} PATH_SUFFIXES lib) - find_library(PThreads_windows_LIBRARY_DEBUG NAMES pthreadsVC2d pthreadVC2d pthreadsVC2 pthreadVC2 PATHS ${PThreads_windows_DIR} PATH_SUFFIXES lib) - select_library_configurations(PThreads_windows) -endif() - -find_package_handle_standard_args(PThreads_windows DEFAULT_MSG PThreads_windows_LIBRARY PThreads_windows_INCLUDE_DIR) -mark_as_advanced(PThreads_windows_INCLUDE_DIR PThreads_windows_LIBRARY) - -set(PThreads_windows_DLL_DIR ${PThreads_windows_INCLUDE_DIR}) -list(TRANSFORM PThreads_windows_DLL_DIR APPEND "/../bin") -message(STATUS "PThreads_windows_DLL_DIR: ${PThreads_windows_DLL_DIR}") - -find_file(PThreads_windows_LIBRARY_RELEASE_DLL NAMES pthreadVC2.dll PATHS ${PThreads_windows_DLL_DIR}) -find_file(PThreads_windows_LIBRARY_DEBUG_DLL NAMES pthreadVC2d.dll pthreadVC2.dll PATHS ${PThreads_windows_DLL_DIR}) - -# Register imported libraries: -# 1. If we can find a Windows .dll file (or if we can find both Debug and -# Release libraries), we will set appropriate target properties for these. -# 2. However, for most systems, we will only register the import location and -# include directory. - -if( PThreads_windows_FOUND AND NOT TARGET PThreads_windows::PThreads_windows ) - if( EXISTS "${PThreads_windows_LIBRARY_RELEASE_DLL}" ) - add_library( PThreads_windows::PThreads_windows SHARED IMPORTED ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads_windows_LIBRARY_RELEASE_DLL}" - IMPORTED_IMPLIB "${PThreads_windows_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads_windows_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads_windows_LIBRARY_DEBUG_DLL}" ) - set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads_windows_LIBRARY_DEBUG_DLL}" - IMPORTED_IMPLIB_DEBUG "${PThreads_windows_LIBRARY_DEBUG}" ) - endif() - else() - add_library( PThreads_windows::PThreads_windows UNKNOWN IMPORTED ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_RELEASE "${PThreads_windows_LIBRARY_RELEASE}" - INTERFACE_INCLUDE_DIRECTORIES "${PThreads_windows_INCLUDE_DIR}" - IMPORTED_CONFIGURATIONS Release - IMPORTED_LINK_INTERFACE_LANGUAGES "C" ) - if( EXISTS "${PThreads_windows_LIBRARY_DEBUG}" ) - set_property( TARGET PThreads_windows::PThreads_windows APPEND PROPERTY IMPORTED_CONFIGURATIONS Debug ) - set_target_properties( PThreads_windows::PThreads_windows PROPERTIES - IMPORTED_LOCATION_DEBUG "${PThreads_windows_LIBRARY_DEBUG}" ) - endif() - endif() -endif()