diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index 5f1cc16e..dc3e2935 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -74,107 +74,11 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio") list(APPEND config_types ${CMAKE_BUILD_TYPE}) endif() -############# -## GTEST ## -############# -message(STATUS "Subproject: GTEST...") -if(USE_SYSTEM_GTEST) - find_package(GTest REQUIRED) -else() - # Download and unpack googletest at configure time - foreach(config ${config_types}) - CONF_PACKAGE(googletest ${config} "") - BUILD_PACKAGE(googletest ${config}) - endforeach() - - # Set variables - SET(GTEST_ROOT "${EP_BASE_DIR}/googletest" PARENT_SCOPE) - SET(GTEST_INCLUDE_DIRS "${EP_BASE_DIR}/googletest/include" PARENT_SCOPE) -endif() -message(STATUS "Subproject: GTEST...DONE") - - -############## -### EIGEN ## -############## -message(STATUS "Subproject: EIGEN...") -if(USE_SYSTEM_EIGEN) - find_package(Eigen3 3.3 REQUIRED NO_MODULE) -else() - CONF_PACKAGE(eigen ${CMAKE_BUILD_TYPE} @ONLY) - BUILD_PACKAGE(eigen ${CMAKE_BUILD_TYPE}) - - # Set variables - SET(Eigen3_DIR "${EP_BASE_DIR}/eigen/share/eigen3/cmake" PARENT_SCOPE) -endif() -message(STATUS "Subproject: EIGEN...DONE") - - -################ -## PROTOBUF ## -################ -if(USE_SYSTEM_PROTOBUF) - find_package(Protobuf REQUIRED) -else() - # Download and unpack protobuf at configure time - foreach(config ${config_types}) - CONF_PACKAGE(protobuf ${config} @ONLY) - BUILD_PACKAGE(protobuf ${config}) - endforeach() - - set(Protobuf_ROOT "${EP_BASE_DIR}/protobuf" PARENT_SCOPE) - set(Protobuf_INCLUDE_DIRS "${EP_BASE_DIR}/protobuf/include" PARENT_SCOPE) - set(Protobuf_PROTOC_EXECUTABLE "${EP_BASE_DIR}/protobuf/bin/protoc" PARENT_SCOPE) - set(Protobuf_USE_STATIC_LIBS ON PARENT_SCOPE) # Always static when superbuild is enabled -endif() add_custom_target(protobuf_files protoc --cpp_out=../src/serialization/onnx ../src/serialization/onnx/onnx.proto ) -message(STATUS "Subproject: Protobuf...DONE") - - -# Only for distributed versions -if(BUILD_DIST) - - ############ - ## ZLIB ## - ############ - message(STATUS "Subproject: ZLIB...") - if(USE_SYSTEM_ZLIB) - find_package(ZLIB REQUIRED) - else() - # Download and unpack ZLIB at configure time - foreach(config ${config_types}) - CONF_PACKAGE(zlib ${config} "") - BUILD_PACKAGE(zlib ${config}) - endforeach() - # Set variables - SET(ZLIB_ROOT "${EP_BASE_DIR}/zlib" PARENT_SCOPE) - SET(ZLIB_INCLUDE_DIRS "${EP_BASE_DIR}/zlib/include" PARENT_SCOPE) - endif() - message(STATUS "Subproject: ZLIB...DONE") - ############### - ## OPENSSL ## - ############### - message(STATUS "Subproject: OpenSSL...") - if(USE_SYSTEM_OPENSSL) - find_package(OpenSSL REQUIRED) - else() - # Download and unpack ZLIB at configure time - foreach(config ${config_types}) - CONF_PACKAGE(openssl ${config} "") - BUILD_PACKAGE(openssl ${config}) - endforeach() - # Set variables - SET(OPENSSL_ROOT_DIR "${EP_BASE_DIR}/openssl" PARENT_SCOPE) - SET(OPENSSL_INCLUDE_DIR "${EP_BASE_DIR}/openssl/include" PARENT_SCOPE) - endif() - message(STATUS "Subproject: OpenSSL...DONE") - -endif() - ################## ## PTHREADS4W ## ################## diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 27d85610..18183b25 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ SET(USE_RISCV OFF) SET(USE_CUDA OFF) SET(USE_CUDNN OFF) SET(USE_FPGA OFF) -SET(USE_PROTOBUF OFF) +SET(USE_PROTOBUF ON) # Device specific setup string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) # Detect cpu, Cpu, CPU,... @@ -59,10 +59,6 @@ file(GLOB_RECURSE PUBLIC_HEADERS "${PROJECT_SOURCE_DIR}/include/*" *.{h, hpp}) file(GLOB_RECURSE CPP_HEADERS "${PROJECT_SOURCE_DIR}/src/*" *.{h, hpp}) file(GLOB_RECURSE CPP_SOURCES "${PROJECT_SOURCE_DIR}/src/*" *.{cc, cpp}) -# Remove dependent files of protobuf -list(FILTER PUBLIC_HEADERS EXCLUDE REGEX ".*/include/eddl/serialization/onnx/onnx.pb*") -list(FILTER CPP_HEADERS EXCLUDE REGEX ".*/src/serialization/onnx/onnx_third_party/onnx.pb*") -list(FILTER CPP_SOURCES EXCLUDE REGEX ".*/src/serialization/onnx/onnx_third_party/onnx.pb*") # Remove problematic files if they are not needed if(NOT BUILD_DIST) @@ -99,7 +95,6 @@ ENDFOREACH(item) # Make an automatic library - will be static or dynamic based on user setting add_library(${PROJECT_NAME} ${ALL_FILES}) - # We need this directory, and users of our library will need it too target_include_directories(${PROJECT_NAME} PUBLIC @@ -139,60 +134,26 @@ endif() ########################### LINK LIBRARIES ################################ ########################################################################### -# Eigen *************************************** -find_package(Eigen3 3.3 REQUIRED NO_MODULE) # EIGEN_DIR => ok -target_include_directories(${PROJECT_NAME} PRIVATE ${EIGEN3_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen) # Header only library - -# Protobuf *************************************** -if(BUILD_PROTOBUF) - - # Link library - if(Protobuf_ROOT) - # Find libraries (need absolute paths) - find_library(Protobuf_LIBRARY NAMES protobuf libprotobuf HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") - find_library(Protobuf_LIBRARY_DEBUG NAMES protobufd libprotobufd HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") - find_library(Protobuf_LIBRARY_RELEASE NAMES protobuf libprotobuf HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") - else() - find_package(Protobuf) # Problems with: Protobuf_ROOT - endif() - - # Check if Protobuf was really found - if(Protobuf_LIBRARY OR Protobuf_FOUND) - # Add extra files - target_sources(${PROJECT_NAME} PRIVATE ${ONNX_FILES}) +# PROTOBUF *************************************** +# Find libraries (need absolute paths) +find_library(Protobuf_LIBRARY NAMES protobuf libprotobuf HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") +find_library(Protobuf_LIBRARY_DEBUG NAMES protobufd libprotobufd HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") +find_library(Protobuf_LIBRARY_RELEASE NAMES protobuf libprotobuf HINTS ${Protobuf_ROOT} PATHS ${Protobuf_ROOT} PATH_SUFFIXES "lib" "lib64") - # Add includes - target_include_directories(${PROJECT_NAME} PUBLIC $) +# Add extra files +target_sources(${PROJECT_NAME} PRIVATE ${ONNX_FILES}) - if(MSVC AND NOT Protobuf_USE_STATIC_LIBS) - # libprotobuf as shared lib requires PROTOBUF_USE_DLLS definition for MSVC :( - # Because of https://github.com/protocolbuffers/protobuf/issues/2502#issuecomment-412868718 - # libprotobuf conda package is dynamically linked - target_compile_definitions(${PROJECT_NAME} PUBLIC PROTOBUF_USE_DLLS) - endif() +# Add includes +target_include_directories(${PROJECT_NAME} PRIVATE ${Protobuf_INCLUDE_DIRS}) - # Add libraries - if(MSVC) - target_link_libraries(${PROJECT_NAME} PUBLIC optimized ${Protobuf_LIBRARY} debug ${Protobuf_LIBRARY_DEBUG}) - else() - target_link_libraries(${PROJECT_NAME} PUBLIC ${Protobuf_LIBRARY}) - endif() +# Add libraries +target_link_libraries(${PROJECT_NAME} PRIVATE ${Protobuf_LIBRARY}) - # Create "onnx.pb.cc" and "onnx.pb.h" files (from serialization/onnx) - # Equivalent to: /usr/local/bin/protoc --cpp_out . onnx.proto - #if(OVERWRITE_PROTO_FILES) - # EXEC_PROGRAM(${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ --proto_path ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ onnx.proto ) - #endif() - SET(USE_PROTOBUF ON) - else() - message(WARNING "[WARNING] Protobuf was requested but it has not been found (Falling back to: '-D BUILD_PROTOBUF=OFF') - Hint: Use '-D BUILD_SUPERBUILD=ON', or try with a different protobuf installation to fix this problem.") - SET(USE_PROTOBUF OFF) - endif() -endif() -SET(USE_PROTOBUF ${USE_PROTOBUF} PARENT_SCOPE) # Parent's scope +SET(USE_PROTOBUF ON) +# EIGEN *************************************** +# Add includes +target_include_directories(${PROJECT_NAME} PUBLIC ${EIGEN3_INCLUDE_DIR}) # OpenMP *************************************** if(BUILD_OPENMP)