option to build project using cpp compiler if c not working/available

This commit is contained in:
Stefano Sinigardi 2019-07-23 15:59:02 +02:00
parent 6daa15b84f
commit ae0306e851
10 changed files with 59 additions and 15 deletions

2
.gitignore vendored
View File

@ -8,6 +8,7 @@
*.exe *.exe
*.dll *.dll
*.lib *.lib
*.dylib
mnist/ mnist/
data/ data/
caffe/ caffe/
@ -31,6 +32,7 @@ build/CMakeFiles/
build/detect_cuda_compute_capabilities.cu build/detect_cuda_compute_capabilities.cu
build/.ninja_deps build/.ninja_deps
build/.ninja_log build/.ninja_log
build/Makefile
# OS Generated # # OS Generated #
.DS_Store* .DS_Store*

View File

@ -44,6 +44,13 @@ matrix:
- additional_defines="" - additional_defines=""
- MATRIX_EVAL="" - MATRIX_EVAL=""
- os: osx
compiler: clang
name: macOS - native clang - C++ mode
env:
- additional_defines="-DBUILD_AS_CPP:BOOL=TRUE"
- MATRIX_EVAL=""
- os: osx - os: osx
compiler: clang compiler: clang
name: macOS - native clang - opencv@2 name: macOS - native clang - opencv@2
@ -179,6 +186,16 @@ matrix:
- additional_defines="" - additional_defines=""
- MATRIX_EVAL="" - MATRIX_EVAL=""
- os: linux
compiler: gcc
name: ubuntu 14.04 - native gcc - C++ mode
addons:
apt:
update: true
env:
- additional_defines="-DBUILD_AS_CPP:BOOL=TRUE"
- MATRIX_EVAL=""
- os: linux - os: linux
compiler: gcc compiler: gcc
name: ubuntu 14.04 - gcc@4.9 name: ubuntu 14.04 - gcc@4.9
@ -942,7 +959,6 @@ install:
- popd - popd
before_script: before_script:
- echo ${additional_defines}
- mkdir build_debug - mkdir build_debug
- cd build_debug - cd build_debug
- cmake .. -DCMAKE_BUILD_TYPE="Debug" ${VCPKG_DEFINES} ${additional_defines} - cmake .. -DCMAKE_BUILD_TYPE="Debug" ${VCPKG_DEFINES} ${additional_defines}

View File

@ -7,6 +7,7 @@ set(Darknet_VERSION ${Darknet_MAJOR_VERSION}.${Darknet_MINOR_VERSION}.${Darknet_
set(CMAKE_VERBOSE_MAKEFILE "FALSE" CACHE BOOL "Create verbose makefile") set(CMAKE_VERBOSE_MAKEFILE "FALSE" CACHE BOOL "Create verbose makefile")
set(BUILD_SHARED_LIBS "TRUE" CACHE BOOL "Create dark as a shared library") set(BUILD_SHARED_LIBS "TRUE" CACHE BOOL "Create dark as a shared library")
set(BUILD_AS_CPP "FALSE" CACHE BOOL "Build Darknet using C++ compiler also for C files")
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE) if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "") set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake" CACHE STRING "")
@ -265,7 +266,9 @@ if(ENABLE_CUDA)
file(GLOB cuda_sources "${CMAKE_CURRENT_LIST_DIR}/src/*.cu") file(GLOB cuda_sources "${CMAKE_CURRENT_LIST_DIR}/src/*.cu")
endif() endif()
#set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX) if(BUILD_AS_CPP)
set_source_files_properties(${sources} PROPERTIES LANGUAGE CXX)
endif()
add_library(dark ${CMAKE_CURRENT_LIST_DIR}/include/yolo_v2_class.hpp ${CMAKE_CURRENT_LIST_DIR}/src/yolo_v2_class.cpp ${sources} ${headers} ${cuda_sources}) add_library(dark ${CMAKE_CURRENT_LIST_DIR}/include/yolo_v2_class.hpp ${CMAKE_CURRENT_LIST_DIR}/src/yolo_v2_class.cpp ${sources} ${headers} ${cuda_sources})
set_target_properties(dark PROPERTIES POSITION_INDEPENDENT_CODE ON) set_target_properties(dark PROPERTIES POSITION_INDEPENDENT_CODE ON)
@ -275,18 +278,24 @@ endif()
if(BUILD_SHARED_LIBS) if(BUILD_SHARED_LIBS)
target_compile_definitions(dark PRIVATE LIB_EXPORTS=1) target_compile_definitions(dark PRIVATE LIB_EXPORTS=1)
endif() endif()
#set_target_properties(dark PROPERTIES LINKER_LANGUAGE CXX) if(BUILD_AS_CPP)
set_target_properties(dark PROPERTIES LINKER_LANGUAGE CXX)
endif()
if(OpenCV_FOUND AND OpenCV_VERSION VERSION_GREATER "3.0" AND NOT SKIP_USELIB_TRACK) if(OpenCV_FOUND AND OpenCV_VERSION VERSION_GREATER "3.0" AND NOT SKIP_USELIB_TRACK)
add_executable(uselib_track ${CMAKE_CURRENT_LIST_DIR}/src/yolo_console_dll.cpp) add_executable(uselib_track ${CMAKE_CURRENT_LIST_DIR}/src/yolo_console_dll.cpp)
endif() endif()
add_executable(uselib ${CMAKE_CURRENT_LIST_DIR}/src/yolo_console_dll.cpp) add_executable(uselib ${CMAKE_CURRENT_LIST_DIR}/src/yolo_console_dll.cpp)
#set_target_properties(uselib PROPERTIES LINKER_LANGUAGE CXX) if(BUILD_AS_CPP)
set_target_properties(uselib PROPERTIES LINKER_LANGUAGE CXX)
endif()
add_executable(darknet ${CMAKE_CURRENT_LIST_DIR}/src/darknet.c ${sources} ${headers} ${cuda_sources}) add_executable(darknet ${CMAKE_CURRENT_LIST_DIR}/src/darknet.c ${sources} ${headers} ${cuda_sources})
#set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/darknet.c PROPERTIES LANGUAGE CXX) if(BUILD_AS_CPP)
#set_target_properties(darknet PROPERTIES LINKER_LANGUAGE CXX) set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/darknet.c PROPERTIES LANGUAGE CXX)
set_target_properties(darknet PROPERTIES LINKER_LANGUAGE CXX)
endif()
target_include_directories(darknet PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> $<INSTALL_INTERFACE:${DARKNET_INSTALL_INCLUDE_DIR}> $<BUILD_INTERFACE:${Stb_INCLUDE_DIR}>) target_include_directories(darknet PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> $<INSTALL_INTERFACE:${DARKNET_INSTALL_INCLUDE_DIR}> $<BUILD_INTERFACE:${Stb_INCLUDE_DIR}>)
target_include_directories(dark PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> $<INSTALL_INTERFACE:${DARKNET_INSTALL_INCLUDE_DIR}> $<BUILD_INTERFACE:${Stb_INCLUDE_DIR}>) target_include_directories(dark PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include> $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/src> $<INSTALL_INTERFACE:${DARKNET_INSTALL_INCLUDE_DIR}> $<BUILD_INTERFACE:${Stb_INCLUDE_DIR}>)
@ -369,7 +378,9 @@ if(OpenCV_FOUND AND OpenCV_VERSION VERSION_GREATER "3.0" AND NOT SKIP_USELIB_TRA
target_link_libraries(uselib_track PRIVATE dark) target_link_libraries(uselib_track PRIVATE dark)
target_compile_definitions(uselib_track PRIVATE TRACK_OPTFLOW=1) target_compile_definitions(uselib_track PRIVATE TRACK_OPTFLOW=1)
target_compile_definitions(uselib_track PRIVATE -DUSE_CMAKE_LIBS) target_compile_definitions(uselib_track PRIVATE -DUSE_CMAKE_LIBS)
#set_target_properties(uselib_track PROPERTIES LINKER_LANGUAGE CXX) if(BUILD_AS_CPP)
set_target_properties(uselib_track PROPERTIES LINKER_LANGUAGE CXX)
endif()
target_include_directories(uselib_track PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include) target_include_directories(uselib_track PRIVATE ${CMAKE_CURRENT_LIST_DIR}/include)
target_link_libraries(uselib_track PRIVATE ${OpenCV_LINKED_COMPONENTS}) target_link_libraries(uselib_track PRIVATE ${OpenCV_LINKED_COMPONENTS})
if(ENABLE_ZED_CAMERA) if(ENABLE_ZED_CAMERA)

View File

@ -37,6 +37,11 @@ environment:
COMPILER: vs COMPILER: vs
configuration: Release configuration: Release
USE_INTEGRATED_LIBS: yes USE_INTEGRATED_LIBS: yes
- platform: Win64
COMPILER: vs
configuration: Release
USE_INTEGRATED_LIBS: yes
FORCE_CPP: yes
install: install:
- if [%COMPILER%]==[vs] cinst cmake ninja - if [%COMPILER%]==[vs] cinst cmake ninja
@ -77,7 +82,8 @@ install:
- mkdir build_release && cd build_release - mkdir build_release && cd build_release
- if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release"' - if [%COMPILER%]==[cygwin] %CYGSH% 'cmake .. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE="Release"'
- if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%configuration%]==[Release] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_BUILD_TYPE="Release" .. - if [%COMPILER%]==[vs] if NOT [%USE_INTEGRATED_LIBS%]==[yes] if [%configuration%]==[Release] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" "-DCMAKE_TOOLCHAIN_FILE=%VCPKG_ROOT%\scripts\buildsystems\vcpkg.cmake" "-DVCPKG_TARGET_TRIPLET=%VCPKG_DEFAULT_TRIPLET%" -DCMAKE_BUILD_TYPE="Release" ..
- if [%COMPILER%]==[vs] if [%USE_INTEGRATED_LIBS%]==[yes] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" -DCMAKE_BUILD_TYPE="Release" .. - if [%COMPILER%]==[vs] if [%USE_INTEGRATED_LIBS%]==[yes] if [%FORCE_CPP%]==[yes] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" -DCMAKE_BUILD_TYPE="Release" "-DBUILD_AS_CPP:BOOL=TRUE" ..
- if [%COMPILER%]==[vs] if [%USE_INTEGRATED_LIBS%]==[yes] cmake -G "Visual Studio 15 2017" -T "host=x64" -A "x64" -DCMAKE_BUILD_TYPE="Release" ..
- cd .. - cd ..
build_script: build_script:

View File

@ -3,6 +3,7 @@
$number_of_build_workers=8 $number_of_build_workers=8
$use_vcpkg=$true $use_vcpkg=$true
$use_ninja=$false $use_ninja=$false
$force_cpp_build=$false
function getProgramFiles32bit() { function getProgramFiles32bit() {
$out = ${env:PROGRAMFILES(X86)} $out = ${env:PROGRAMFILES(X86)}
@ -149,6 +150,9 @@ if (Test-Path env:CUDA_PATH) {
} }
} }
if($force_cpp_build) {
$additional_build_setup="-DBUILD_AS_CPP:BOOL=TRUE"
}
if ($use_vcpkg) { if ($use_vcpkg) {
## DEBUG ## DEBUG

View File

@ -2,12 +2,9 @@
number_of_build_workers=8 number_of_build_workers=8
bypass_vcpkg=true bypass_vcpkg=true
force_cpp_build=false
if [[ "$OSTYPE" == "darwin"* ]]; then if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ "$1" == "gcc" ]]; then
export CC="/usr/local/bin/gcc-8"
export CXX="/usr/local/bin/g++-8"
fi
vcpkg_triplet="x64-osx" vcpkg_triplet="x64-osx"
else else
vcpkg_triplet="x64-linux" vcpkg_triplet="x64-linux"
@ -30,6 +27,11 @@ then
(>&2 echo "darknet is unsupported without vcpkg, use at your own risk!") (>&2 echo "darknet is unsupported without vcpkg, use at your own risk!")
fi fi
if [ "$force_cpp_build" = true ]
then
additional_build_setup="-DBUILD_AS_CPP:BOOL=TRUE"
fi
## DEBUG ## DEBUG
#mkdir -p build_debug #mkdir -p build_debug
#cd build_debug #cd build_debug

View File

@ -1,5 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <string.h>
#include "col2im.h" #include "col2im.h"
void col2im_add_pixel(float *im, int height, int width, int channels, void col2im_add_pixel(float *im, int height, int width, int channels,
int row, int col, int channel, int pad, float val) int row, int col, int channel, int pad, float val)

View File

@ -937,7 +937,7 @@ data load_data_detection(int n, char **paths, int m, int w, int h, int c, int bo
{ {
image tmp_ai = copy_image(ai); image tmp_ai = copy_image(ai);
char buff[1000]; char buff[1000];
sprintf(buff, "aug_%d_%d_%s_%d", random_index, i, basecfg(filename), random_gen()); sprintf(buff, "aug_%d_%d_%s_%d", random_index, i, basecfg((char*)filename), random_gen());
int t; int t;
for (t = 0; t < boxes; ++t) { for (t = 0; t < boxes; ++t) {
box b = float_to_box_stride(d.y.vals[i] + t*(4 + 1), 1); box b = float_to_box_stride(d.y.vals[i] + t*(4 + 1), 1);

View File

@ -1120,8 +1120,10 @@ void convolution_2d(int w, int h, int ksize, int n, int c, int pad, int stride,
static inline int popcnt128(__m128i n) { static inline int popcnt128(__m128i n) {
const __m128i n_hi = _mm_unpackhi_epi64(n, n); const __m128i n_hi = _mm_unpackhi_epi64(n, n);
#ifdef _MSC_VER #if defined(_MSC_VER)
return __popcnt64(_mm_cvtsi128_si64(n)) + __popcnt64(_mm_cvtsi128_si64(n_hi)); return __popcnt64(_mm_cvtsi128_si64(n)) + __popcnt64(_mm_cvtsi128_si64(n_hi));
#elif defined(__APPLE__) && defined(__clang__)
return _mm_popcnt_u64(_mm_cvtsi128_si64(n)) + _mm_popcnt_u64(_mm_cvtsi128_si64(n_hi));
#else #else
return __popcntq(_mm_cvtsi128_si64(n)) + __popcntq(_mm_cvtsi128_si64(n_hi)); return __popcntq(_mm_cvtsi128_si64(n)) + __popcntq(_mm_cvtsi128_si64(n_hi));
#endif #endif

View File

@ -167,7 +167,7 @@ convolutional_layer parse_convolutional(list *options, size_params params, netwo
int share_index = option_find_int_quiet(options, "share_index", -1); int share_index = option_find_int_quiet(options, "share_index", -1);
convolutional_layer *share_layer = NULL; convolutional_layer *share_layer = NULL;
if(share_layer > -1) share_layer = &net.layers[share_index]; if((long long int)share_layer > -1) share_layer = &net.layers[share_index];
int batch,h,w,c; int batch,h,w,c;
h = params.h; h = params.h;