diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c3331654ac..8587793345a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ option(ENABLE_ZED_CAMERA "Enable ZED Camera support" ON) option(ENABLE_VCPKG_INTEGRATION "Enable VCPKG integration" OFF) option(ENABLE_DEPLOY_CUSTOM_CMAKE_MODULES "Copy custom CMake modules for downstream integration" OFF) option(ENABLE_CSHARP_WRAPPER "Enable building a csharp wrapper" OFF) +option(ENABLE_INSTALLER "Enable building an installer" OFF) option(VCPKG_BUILD_OPENCV_WITH_CUDA "Build OpenCV with CUDA extension integration" ON) option(VCPKG_USE_OPENCV2 "Use legacy OpenCV 2" OFF) option(VCPKG_USE_OPENCV3 "Use legacy OpenCV 3" OFF) @@ -161,12 +162,17 @@ if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) "Debug" "Release" "MinSizeRel" "RelWithDebInfo") endif() -if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) - set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Install prefix" FORCE) +if(NOT ENABLE_INSTALLER) + if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Install prefix" FORCE) + endif() + set(INSTALL_BIN_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path where exe and dll will be installed") + set(INSTALL_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path where lib will be installed") +else() + set(INSTALL_BIN_DIR "bin" CACHE PATH "Path where exe and dll will be installed") + set(INSTALL_LIB_DIR "lib" CACHE PATH "Path where lib will be installed") endif() -set(INSTALL_BIN_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path where exe and dll will be installed") -set(INSTALL_LIB_DIR "${CMAKE_CURRENT_LIST_DIR}" CACHE PATH "Path where lib will be installed") set(INSTALL_INCLUDE_DIR "include/darknet" CACHE PATH "Path where headers will be installed") set(INSTALL_CMAKE_DIR "share/darknet" CACHE PATH "Path where cmake configs will be installed") @@ -383,7 +389,6 @@ else() set(ENABLE_ZED_CAMERA "FALSE" CACHE BOOL "Enable ZED Camera support" FORCE) endif() -# Make relative paths absolute (needed later on) foreach(p LIB BIN INCLUDE CMAKE) set(var INSTALL_${p}_DIR) if(NOT IS_ABSOLUTE "${${var}}") @@ -465,6 +470,9 @@ if(BUILD_AS_CPP) set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/darknet.c PROPERTIES LANGUAGE CXX) set_target_properties(darknet PROPERTIES LINKER_LANGUAGE CXX) endif() +if(MSVC) + target_sources(darknet PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src/darknet.rc) +endif() add_executable(kmeansiou ${CMAKE_CURRENT_LIST_DIR}/scripts/kmeansiou.c) if(MATH_LIBRARY) @@ -655,3 +663,37 @@ install( PROGRAMS ${CMAKE_INSTALL_SYSTEM_RUNTIME_LIBS} DESTINATION ${INSTALL_BIN_DIR} ) + +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json) + file(READ ${CMAKE_CURRENT_SOURCE_DIR}/vcpkg.json VCPKG_JSON_STRING) + string(JSON CPACK_PACKAGE_NAME GET ${VCPKG_JSON_STRING} name) + string(JSON CPACK_BUNDLE_NAME GET ${VCPKG_JSON_STRING} name) + string(JSON CPACK_PACKAGE_HOMEPAGE_URL GET ${VCPKG_JSON_STRING} homepage) + string(JSON CPACK_PACKAGE_DESCRIPTION GET ${VCPKG_JSON_STRING} description) + string(JSON CPACK_NSIS_DISPLAY_NAME GET ${VCPKG_JSON_STRING} description) + string(JSON CPACK_NSIS_PACKAGE_NAME GET ${VCPKG_JSON_STRING} description) + set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE) + set(CPACK_NSIS_MUI_ICON "${CMAKE_CURRENT_SOURCE_DIR}/src/darknet.ico") + set(CPACK_NSIS_MUI_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/src/darknet.ico") + set(CPACK_BUNDLE_UNIICON "${CMAKE_CURRENT_SOURCE_DIR}/src/darknet.ico") + + if(UNIX AND NOT APPLE) + find_program(LSB_RELEASE_EXEC lsb_release) + execute_process(COMMAND ${LSB_RELEASE_EXEC} -is + OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(LSB_RELEASE_ID_SHORT STREQUAL "Ubuntu") + set(CPACK_GENERATOR "DEB") + else() + set(CPACK_GENERATOR "RPM") + endif() + elseif(WIN32) + set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) + set(CPACK_NSIS_MODIFY_PATH "ON") + set(CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL "ON") + set(CPACK_GENERATOR "NSIS") + endif() + + include(CPack) +endif() diff --git a/build.ps1 b/build.ps1 index 354f05df5a1..b9e3205569e 100755 --- a/build.ps1 +++ b/build.ps1 @@ -6,7 +6,7 @@ build Created By: Stefano Sinigardi Created Date: February 18, 2019 - Last Modified Date: August 10, 2023 + Last Modified Date: August 31, 2023 .DESCRIPTION Build tool using CMake, trying to properly setup the environment around compiler @@ -110,6 +110,9 @@ Download pre-trained weight files .PARAMETER Use32bitTriplet Use 32 bit triplet for target build (windows-only) +.PARAMETER BuildInstaller +Build an installer using CPack + .PARAMETER ForceGCCVersion Force a specific GCC version @@ -182,6 +185,7 @@ param ( [switch]$EnableCSharpWrapper = $false, [switch]$DownloadWeights = $false, [switch]$Use32bitTriplet = $false, + [switch]$BuildInstaller = $false, [Int32]$ForceGCCVersion = 0, [Int32]$NumberOfBuildWorkers = 8, [string]$AdditionalBuildSetup = "" # "-DCMAKE_CUDA_ARCHITECTURES=30" @@ -189,7 +193,7 @@ param ( $global:DisableInteractive = $DisableInteractive -$build_ps1_version = "3.4.1" +$build_ps1_version = "3.5.0" $script_name = $MyInvocation.MyCommand.Name Import-Module -Name $PSScriptRoot/scripts/utils.psm1 -Force @@ -881,6 +885,15 @@ if (-Not $InstallDARKNETthroughVCPKG) { $AdditionalBuildSetup = $AdditionalBuildSetup + " -DENABLE_DEPLOY_CUSTOM_CMAKE_MODULES:BOOL=ON" } +if ($ForceVCPKGBuildtreesPath -ne "") { + $AdditionalBuildSetup = $AdditionalBuildSetup + " -DVCPKG_INSTALL_OPTIONS=`"--x-buildtrees-root=$ForceVCPKGBuildtreesPath`" " + New-Item -Path $ForceVCPKGBuildtreesPath -ItemType directory -Force | Out-Null + $vcpkgbuildtreespath = "$ForceVCPKGBuildtreesPath" +} +else { + $vcpkgbuildtreespath = "$vcpkg_path/buildtrees" +} + if ($InstallDARKNETthroughVCPKG) { if ($ForceVCPKGDarknetHEAD) { $headMode = " --head " @@ -979,10 +992,6 @@ else { Write-Host "-- Copying $_ to $DebugInstallPrefix/bin" Copy-Item $_ $DebugInstallPrefix/bin } - if (-Not $DoNotDeleteBuildFolder) { - Write-Host "Removing folder $debug_build_folder" -ForegroundColor Yellow - Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $debug_build_folder - } } $release_build_folder = "$PSCustomScriptRoot/build_release" if (-Not $DoNotDeleteBuildFolder) { @@ -1010,19 +1019,22 @@ else { if (-Not ($exitCode -eq 0)) { MyThrow("Build failed! Exited with error code $exitCode.") } - Remove-Item -Force -ErrorAction SilentlyContinue DarknetConfig.cmake - Remove-Item -Force -ErrorAction SilentlyContinue DarknetConfigVersion.cmake if (-Not $UseVCPKG -And -Not $DisableDLLcopy) { $dllfiles = Get-ChildItem ./${dllfolder}/*.dll if ($dllfiles) { Copy-Item $dllfiles .. } } - if (-Not $DoNotDeleteBuildFolder) { - Write-Host "Removing folder $release_build_folder" -ForegroundColor Yellow - Remove-Item -Force -Recurse -ErrorAction SilentlyContinue $release_build_folder + if ($BuildInstaller) { + Write-Host "Building package with CPack" -ForegroundColor Green + $proc = Start-Process -NoNewWindow -PassThru -FilePath $CMAKE_EXE -ArgumentList "--build . --target package" + $handle = $proc.Handle + $proc.WaitForExit() + $exitCode = $proc.ExitCode + if (-Not ($exitCode -eq 0)) { + MyThrow("Packaging failed! Exited with error code $exitCode.") + } } - Set-Location .. } Pop-Location diff --git a/src/art.c b/src/art.c index d90290fcbc2..748e19038dc 100644 --- a/src/art.c +++ b/src/art.c @@ -40,8 +40,7 @@ void demo_art(char *cfgfile, char *weightfile, int cam_index) float *p = network_predict(net, in_s.data); - printf("\033[2J"); - printf("\033[1;1H"); + printf("\033[H\033[J"); float score = 0; for(i = 0; i < n; ++i){ diff --git a/src/classifier.c b/src/classifier.c index c17e1b1ffe7..0c81aee4e27 100644 --- a/src/classifier.c +++ b/src/classifier.c @@ -1129,11 +1129,8 @@ void threat_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_i sprintf(buff, "tmp/threat_%06d", count); //save_image(out, buff); -#ifndef _WIN32 - printf("\033[2J"); - printf("\033[1;1H"); -#endif - printf("\nFPS:%.0f\n",fps); + printf("\033[H\033[J"); + printf("\nFPS:%.0f\n", fps); for(i = 0; i < top; ++i){ int index = indexes[i]; @@ -1208,8 +1205,7 @@ void gun_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_inde float *predictions = network_predict(net, in_s.data); top_predictions(net, top, indexes); - printf("\033[2J"); - printf("\033[1;1H"); + printf("\033[H\033[J"); int threat = 0; for(i = 0; i < sizeof(bad_cats)/sizeof(bad_cats[0]); ++i){ @@ -1308,11 +1304,7 @@ void demo_classifier(char *datacfg, char *cfgfile, char *weightfile, int cam_ind if(net.hierarchy) hierarchy_predictions(predictions, net.outputs, net.hierarchy, 1); top_predictions(net, top, indexes); -#ifndef _WIN32 - printf("\033[2J"); - printf("\033[1;1H"); -#endif - + printf("\033[H\033[J"); if (!benchmark) { printf("\rFPS: %.2f (use -benchmark command line flag for correct measurement)\n", fps); diff --git a/src/darknet.ico b/src/darknet.ico new file mode 100644 index 00000000000..358c53f3089 Binary files /dev/null and b/src/darknet.ico differ diff --git a/src/darknet.rc b/src/darknet.rc new file mode 100644 index 00000000000..8c5a7d54840 --- /dev/null +++ b/src/darknet.rc @@ -0,0 +1 @@ +1 ICON "darknet.ico" diff --git a/src/demo.c b/src/demo.c index 2c48bb78749..e9017a0bd8c 100644 --- a/src/demo.c +++ b/src/demo.c @@ -280,8 +280,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int if (l.embedding_size) set_track_id(local_dets, local_nboxes, demo_thresh, l.sim_thresh, l.track_ciou_norm, l.track_history_size, l.dets_for_track, l.dets_for_show); - //printf("\033[2J"); - //printf("\033[1;1H"); + printf("\033[H\033[J"); //printf("\nFPS:%.1f\n", fps); printf("Objects:\n\n"); diff --git a/src/detector.c b/src/detector.c index 6f050986615..3799063187b 100644 --- a/src/detector.c +++ b/src/detector.c @@ -314,14 +314,13 @@ void train_detector(char *datacfg, char *cfgfile, char *weightfile, int *gpus, i if (mean_average_precision > 0) printf("\n Last accuracy mAP@%0.2f = %2.2f %%, best = %2.2f %% ", iou_thresh, mean_average_precision * 100, best_map * 100); } - #ifndef WIN32 + printf("\033[H\033[J"); if (mean_average_precision > 0.0) { - printf("\033]2;%d/%d: loss=%0.1f map=%0.2f best=%0.2f hours left=%0.1f\007", iteration, net.max_batches, loss, mean_average_precision, best_map, avg_time); + printf("%d/%d: loss=%0.1f map=%0.2f best=%0.2f hours left=%0.1f\007", iteration, net.max_batches, loss, mean_average_precision, best_map, avg_time); } else { - printf("\033]2;%d/%d: loss=%0.1f hours left=%0.1f\007", iteration, net.max_batches, loss, avg_time); + printf("%d/%d: loss=%0.1f hours left=%0.1f\007", iteration, net.max_batches, loss, avg_time); } - #endif if (net.cudnn_half) { if (iteration < net.burn_in * 3) fprintf(stderr, "\n Tensor Cores are disabled until the first %d iterations are reached.\n", 3 * net.burn_in);