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
*.dll
*.lib
*.dylib
mnist/
data/
caffe/
@ -31,6 +32,7 @@ build/CMakeFiles/
build/detect_cuda_compute_capabilities.cu
build/.ninja_deps
build/.ninja_log
build/Makefile
# OS Generated #
.DS_Store*

View File

@ -44,6 +44,13 @@ matrix:
- additional_defines=""
- MATRIX_EVAL=""
- os: osx
compiler: clang
name: macOS - native clang - C++ mode
env:
- additional_defines="-DBUILD_AS_CPP:BOOL=TRUE"
- MATRIX_EVAL=""
- os: osx
compiler: clang
name: macOS - native clang - opencv@2
@ -179,6 +186,16 @@ matrix:
- additional_defines=""
- 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
compiler: gcc
name: ubuntu 14.04 - gcc@4.9
@ -942,7 +959,6 @@ install:
- popd
before_script:
- echo ${additional_defines}
- mkdir build_debug
- cd build_debug
- 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(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)
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")
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})
set_target_properties(dark PROPERTIES POSITION_INDEPENDENT_CODE ON)
@ -275,18 +278,24 @@ endif()
if(BUILD_SHARED_LIBS)
target_compile_definitions(dark PRIVATE LIB_EXPORTS=1)
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)
add_executable(uselib_track ${CMAKE_CURRENT_LIST_DIR}/src/yolo_console_dll.cpp)
endif()
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})
#set_source_files_properties(${CMAKE_CURRENT_LIST_DIR}/src/darknet.c PROPERTIES LANGUAGE CXX)
#set_target_properties(darknet PROPERTIES LINKER_LANGUAGE CXX)
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()
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}>)
@ -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_compile_definitions(uselib_track PRIVATE TRACK_OPTFLOW=1)
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_link_libraries(uselib_track PRIVATE ${OpenCV_LINKED_COMPONENTS})
if(ENABLE_ZED_CAMERA)

View File

@ -37,6 +37,11 @@ environment:
COMPILER: vs
configuration: Release
USE_INTEGRATED_LIBS: yes
- platform: Win64
COMPILER: vs
configuration: Release
USE_INTEGRATED_LIBS: yes
FORCE_CPP: yes
install:
- if [%COMPILER%]==[vs] cinst cmake ninja
@ -77,7 +82,8 @@ install:
- mkdir build_release && cd build_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 [%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 ..
build_script:

View File

@ -3,6 +3,7 @@
$number_of_build_workers=8
$use_vcpkg=$true
$use_ninja=$false
$force_cpp_build=$false
function getProgramFiles32bit() {
$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) {
## DEBUG

View File

@ -2,12 +2,9 @@
number_of_build_workers=8
bypass_vcpkg=true
force_cpp_build=false
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"
else
vcpkg_triplet="x64-linux"
@ -30,6 +27,11 @@ then
(>&2 echo "darknet is unsupported without vcpkg, use at your own risk!")
fi
if [ "$force_cpp_build" = true ]
then
additional_build_setup="-DBUILD_AS_CPP:BOOL=TRUE"
fi
## DEBUG
#mkdir -p build_debug
#cd build_debug

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "col2im.h"
void col2im_add_pixel(float *im, int height, int width, int channels,
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);
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;
for (t = 0; t < boxes; ++t) {
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) {
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));
#elif defined(__APPLE__) && defined(__clang__)
return _mm_popcnt_u64(_mm_cvtsi128_si64(n)) + _mm_popcnt_u64(_mm_cvtsi128_si64(n_hi));
#else
return __popcntq(_mm_cvtsi128_si64(n)) + __popcntq(_mm_cvtsi128_si64(n_hi));
#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);
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;
h = params.h;