Skip to content

Commit

Permalink
Merge pull request #81 from deephealthproject/install
Browse files Browse the repository at this point in the history
Install
  • Loading branch information
salvacarrion authored Feb 14, 2020
2 parents cf79ec5 + 1e2c4a4 commit f94a0c6
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 57 deletions.
118 changes: 64 additions & 54 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SET(CMAKE_CXX_STANDARD_REQUIRED ON)

# USER OPTIONS *******************************
set(BUILD_TARGET "GPU" CACHE STRING "Compile library for {CPU, GPU, FPGA}")
option(BUILD_EXAMPLES "Compile examples" ON)
option(BUILD_EXAMPLES "Compile examples" OFF)
option(BUILD_TESTS "Compile tests" OFF)
option(BUILD_SHARED_LIB "Whether to build a static or dynamic library" ON)
option(BUILD_HPC "Use aggressive flags that might break the code. Use it carefully." OFF)
Expand Down Expand Up @@ -70,13 +70,15 @@ endif()
# Device specific setup
string(TOUPPER ${BUILD_TARGET} BUILD_TARGET) # Detect cpu, Cpu, CPU,...
if(${BUILD_TARGET} STREQUAL "CPU")
message("Compiling for CPU...")
# message("Compiling for CPU...")
elseif(${BUILD_TARGET} STREQUAL "GPU" OR ${BUILD_TARGET} STREQUAL "CUDA")
message("Compiling for GPU...")
# message("Compiling for GPU...")
set(USE_CUDA ON CACHE BOOL "Enable CUDA support if checked")
elseif(${BUILD_TARGET} STREQUAL "FPGA")
message("Compiling for FPGA...")
# message("Compiling for FPGA...")
message(FATAL_ERROR "FPGA not implemented, CMake will exit." )
else()
message(FATAL_ERROR "Build target not implemented, CMake will exit." )
endif()

# Set default install directories
Expand All @@ -88,6 +90,25 @@ if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
endif()
endif()


# Add CUDA (if possible)
if(USE_CUDA)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr -D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES -D__STRICT_ANSI__")
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
else()
set(USE_CUDA OFF)
set(BUILD_TARGET "CPU")
endif()
endif()


# SHOW OPTIONS
message(STATUS "===========================================" )
message(STATUS "===========================================" )
Expand All @@ -107,22 +128,6 @@ message(STATUS "CUDA flags: " ${CMAKE_CUDA_FLAGS} )
message(STATUS "===========================================" )
message(STATUS "===========================================" )

# Add CUDA (if possible)
if(USE_CUDA)
include(CheckLanguage)
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} --expt-relaxed-constexpr -D_MWAITXINTRIN_H_INCLUDED -D_FORCE_INLINES -D__STRICT_ANSI__")
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
else()
message(WARNING "No CUDA support")
endif()
endif()

# Microsoft Visual C++ - set static/dynamic runtime
if(MSVC)
if(BUILD_SHARED_LIB)
Expand Down Expand Up @@ -150,17 +155,17 @@ if(MSVC)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
endif()

# ONNX
include(FindProtobuf)
find_package(Protobuf REQUIRED)
if(Protobuf_FOUND)
add_compile_definitions(cPROTO)
#protobuf_generate_cpp(onnx.pb.cc onnx.pb.h onnx.proto) #Generate protobuf files #Doesn't work
#EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ --proto_path ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ onnx.proto )
message("-- Protobuf path: ${PROTOBUF_LIBRARIES} ${PROTOBUF_INCLUDE_DIR}")
else()
message(WARNING "Protobuf not found, ignore if you are not using the ONNX module.")
endif()
## ONNX
#include(FindProtobuf)
#find_package(Protobuf REQUIRED)
#if(Protobuf_FOUND)
# add_compile_definitions(cPROTO)
# #protobuf_generate_cpp(onnx.pb.cc onnx.pb.h onnx.proto) #Generate protobuf files #Doesn't work
# #EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ --proto_path ${PROJECT_SOURCE_DIR}/src/serialization/onnx/ onnx.proto )
# message("-- Protobuf path: ${PROTOBUF_LIBRARIES} ${PROTOBUF_INCLUDE_DIR}")
#else()
# message(WARNING "Protobuf not found, ignore if you are not using the ONNX module.")
#endif()


# [MACRO] Download submodules
Expand Down Expand Up @@ -235,7 +240,7 @@ file(GLOB_RECURSE ONNX_SOURCES_FILES
${PROJECT_SOURCE_DIR}/src/serialization/onnx/*.cc
)
SET(ONNX_SOURCES ${ONNX_HEADER_FILES} ${ONNX_SOURCES_FILES})
# SET(ONNX_SOURCES "")
SET(ONNX_SOURCES "")


# [LIBRARY] EDDL LIBRARY *********************
Expand Down Expand Up @@ -310,10 +315,10 @@ if (ZLIB_FOUND)
endif()

#Onnx link
if(Protobuf_FOUND)
target_include_directories(eddl PUBLIC ${PROTOBUF_INCLUDE_DIR})
target_link_libraries(eddl PRIVATE ${PROTOBUF_LIBRARIES})
endif()
#if(Protobuf_FOUND)
# target_include_directories(eddl PUBLIC ${PROTOBUF_INCLUDE_DIR})
# target_link_libraries(eddl PRIVATE ${PROTOBUF_LIBRARIES})
#endif()

# ONNX
# include(FindProtobuf)
Expand Down Expand Up @@ -356,11 +361,11 @@ endif()


# [TESTS] Generate a test executable
if(BUILD_TESTS)
enable_testing()
find_package(GTest REQUIRED)
target_link_libraries(eddl PRIVATE ${GTEST_INCLUDE_DIRS})
endif(BUILD_TESTS)
#if(BUILD_TESTS)
# enable_testing()
# find_package(GTest REQUIRED)
# target_link_libraries(eddl PRIVATE ${GTEST_INCLUDE_DIRS})
#endif(BUILD_TESTS)


# [EXAMPLES] Generate a few test executables
Expand Down Expand Up @@ -433,16 +438,18 @@ if(BUILD_EXAMPLES)
# add_executable(onnx_pointer "${EXAMPLES_DIR}/onnx/1_onnx_pointer.cpp")
# target_link_libraries(onnx_pointer eddl)

add_executable(onnx_export "${EXAMPLES_DIR}/onnx/2_onnx_save_net_to_file.cpp")
target_link_libraries(onnx_export eddl)

add_executable(onnx_import "${EXAMPLES_DIR}/onnx/3_onnx_import_net_from_file.cpp")
target_link_libraries(onnx_import eddl)
# add_executable(onnx_export "${EXAMPLES_DIR}/onnx/2_onnx_save_net_to_file.cpp")
# target_link_libraries(onnx_export eddl)
#
# add_executable(onnx_import "${EXAMPLES_DIR}/onnx/3_onnx_import_net_from_file.cpp")
# target_link_libraries(onnx_import eddl)

endif(BUILD_EXAMPLES)


# [INSTALL] Install the EDDL library
message(STATUS "Install path: ${CMAKE_INSTALL_PREFIX}")

if (WIN32)
SET(EDDL_CONFIG_INSTALL_PATH ${CMAKE_INSTALL_PREFIX})
else()
Expand All @@ -451,20 +458,23 @@ endif()

install(TARGETS eddl
EXPORT eddlTargets
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
install(EXPORT eddlTargets
DESTINATION ${EDDL_CONFIG_INSTALL_PATH}
)
install(EXPORT eddlTargets DESTINATION ${EDDL_CONFIG_INSTALL_PATH})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src/
install(DIRECTORY src/
DESTINATION include/eddl
FILES_MATCHING PATTERN "*.h")

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/eddlConfig.cmake.in ${CMAKE_BINARY_DIR}/cmake/eddlConfig.cmake @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/cmake/eddlConfig.cmake
DESTINATION ${EDDL_CONFIG_INSTALL_PATH})

message(STATUS "Install path: ${CMAKE_INSTALL_PREFIX}")
# This allows to do: "find_package(eddl)"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/eddlConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/eddlConfig.cmake @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/cmake/eddlConfig.cmake"
DESTINATION ${EDDL_CONFIG_INSTALL_PATH}
)

#Experimental script
#file(MAKE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/temp)
Expand Down
20 changes: 18 additions & 2 deletions cmake/eddlConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
include(CMakeFindDependencyMacro)

# VARIABLES
SET(USE_CUDA @USE_CUDA@)
SET(OpenMP_FOUND "@OpenMP_FOUND@")
SET(ZLIB_ROOT "@ZLIB_ROOT@")
#SET(Protobuf_FOUND @Protobuf_FOUND@)

# pthreads setup for linux os
# THREADS (pthreads setup for linux os)
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
SET(CMAKE_THREAD_PREFER_PTHREAD TRUE)
SET(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_dependency(Threads)
endif()

# CUDA
if (${USE_CUDA})
enable_language(CUDA)
endif()

# EIGEN
find_dependency(Eigen3)

# OPENMP
if (${OpenMP_FOUND})
find_dependency(OpenMP)
set(ZLIB_ROOT "@ZLIB_ROOT@")
endif()

# ZLIB
find_dependency(ZLIB)

# PROTOBUF
#if (${Protobuf_FOUND})
# find_dependency(Protobuf)
#endif()

include("@EDDL_CONFIG_INSTALL_PATH@/eddlTargets.cmake")

SET(EDDL_LIBRARIES eddl)
Expand Down
2 changes: 1 addition & 1 deletion scripts/formulas/brew/eddl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def install
test do
(testpath/"test.cpp").write <<~EOS
#include <iostream>
#include <eddl/tensor>
#include <eddl/tensor/tensor.h>
int main(){
Tensor *t1 = Tensor::ones({5, 1});
std::cout << t1->sum() << std::endl;
Expand Down

0 comments on commit f94a0c6

Please sign in to comment.