Skip to content

Commit

Permalink
option to build project using cpp compiler if c not working/available
Browse files Browse the repository at this point in the history
  • Loading branch information
cenit committed Jul 25, 2019
1 parent 6daa15b commit ae0306e
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.exe
*.dll
*.lib
*.dylib
mnist/
data/
caffe/
Expand All @@ -31,6 +32,7 @@ build/CMakeFiles/
build/detect_cuda_compute_capabilities.cu
build/.ninja_deps
build/.ninja_log
build/Makefile

# OS Generated #
.DS_Store*
Expand Down
18 changes: 17 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 - [email protected]
Expand Down Expand Up @@ -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}
Expand Down
23 changes: 17 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 "")
Expand Down Expand Up @@ -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)
Expand All @@ -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}>)
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/col2im.c
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/data.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/gemm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ae0306e

Please sign in to comment.