Skip to content
Snippets Groups Projects
Verified Commit 57fbe767 authored by Timm Fitschen's avatar Timm Fitschen
Browse files

WIP: conan

parent 296735c0
No related branches found
No related tags found
No related merge requests found
Pipeline #9585 canceled
......@@ -87,28 +87,40 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
endif()
####################################################################
## CODE GENERATION (WITH GRPC)
####################################################################
## CODE GENERATION
option(GRPC_FETCHCONTENT "Fetch and build GRPC from the sources" OFF)
include(FetchGRPC)
#
# Protobuf/Grpc source files
#
set(PROTO_FILES
${PROJECT_SOURCE_DIR}/proto/proto/caosdb/info/v1alpha1/main.proto
)
set(PROTO_PATH ${PROJECT_SOURCE_DIR}/proto/proto)
# compiler binaries
set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc")
set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin")
# Generated sources
set(hw_hdrs_path "info/v1alpha1")
set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.pb.cc")
set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.pb.h")
set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.grpc.pb.cc")
set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${hw_hdrs_path}/main.grpc.pb.h")
# compile *proto files to cpp
set(GRPC_GENERATED_HEADERS
"${hw_proto_hdrs}"
"${hw_grpc_hdrs}")
set(GRPC_GENERATED_SOURCES
"${hw_proto_srcs}"
"${hw_grpc_srcs}")
set(GRPC_GENERATED
${GRPC_GENERATED_SOURCES}
${GRPC_GENERATED_HEADERS})
add_custom_command(
OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}"
OUTPUT ${GRPC_GENERATED}
COMMAND ${_PROTOBUF_PROTOC}
ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/include"
--cpp_out "${CMAKE_CURRENT_BINARY_DIR}/include"
......@@ -118,17 +130,11 @@ add_custom_command(
DEPENDS "${PROTO_FILES}")
# hw_grpc_proto
add_library(caosdb_info_v1alpha1
${hw_grpc_srcs}
${hw_grpc_hdrs}
${hw_proto_srcs}
${hw_proto_hdrs})
${GRPC_GENERATED})
target_link_libraries(caosdb_info_v1alpha1
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
${CONAN_LIBS})
target_include_directories(caosdb_info_v1alpha1 PUBLIC
# headers to include when building from source
$<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
......@@ -138,10 +144,7 @@ target_include_directories(caosdb_info_v1alpha1 PUBLIC
target_link_libraries(caosdb
caosdb_info_v1alpha1
${CONAN_LIBS}
${_REFLECTION}
${_GRPC_GRPCPP}
${_PROTOBUF_LIBPROTOBUF})
${CONAN_LIBS})
###############################################
......@@ -236,7 +239,7 @@ install(
## install(FILES ...) simply puts files in a certain place with certain
## properties. We're just copying them to the desired place here.
install(FILES ${libcaosdb_INCL} DESTINATION ${libcaosdb_INCLUDE_DEST})
install(FILES ${hw_grpc_hdrs} ${hw_proto_hdrs}
install(FILES ${GRPC_GENERATED_HEADERS}
DESTINATION ${libcaosdb_INCLUDE_DEST}/${hw_hdrs_path})
install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake
DESTINATION ${libcaosdb_CMAKE_DEST})
......
from conans import ConanFile, CMake, tools
class LibcaosdbConan(ConanFile):
name = "libcaosdb"
version = "0.0.1"
license = "AGPL-3.0-or-later"
author = "Timm C. Fitschen <t.fitschen@indiscale.com>"
url = "https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git"
description = "C++ library for the CaosDB project"
topics = ("data management", "caosdb")
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": False, "fPIC": True}
generators = "cmake"
requires = [("boost/1.76.0"), ("gtest/1.11.0"), ("grpc/1.38.0")]
exports = "*.cpp", "*h"
def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
def source(self):
self.run("git clone https://gitlab.indiscale.com/caosdb/src/caosdb-cpplib.git")
def imports(self):
self.copy("protoc*", "build_tools", "bin")
self.copy("grpc_cpp_plugin", "build_tools", "bin")
def build(self):
cmake = CMake(self)
cmake.configure(source_folder="src")
cmake.build()
# Explicit way:
# self.run('cmake %s/hello %s'
# % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)
def package(self):
self.copy("*.h", dst="include", src="include")
self.copy("*hello.lib", dst="lib", keep_path=False)
self.copy("*.dll", dst="bin", keep_path=False)
self.copy("*.so", dst="lib", keep_path=False)
self.copy("*.dylib", dst="lib", keep_path=False)
self.copy("*.a", dst="lib", keep_path=False)
def package_info(self):
self.cpp_info.libs = ["libcaosdb"]
[requires]
boost/1.76.0
gtest/1.11.0
grpc/1.38.0
[generators]
cmake
[imports]
bin, protoc* -> ./build_tools
bin, grpc_cpp_plugin* -> ./build_tools
......@@ -25,15 +25,15 @@ set(test_cases
)
# download gtest library
include(FetchGTest)
#include(FetchGTest)
# add special cmake functions for gtest
include(GoogleTest)
# disable linting for gtest targets (not our concern)
set_target_properties(gmock_main gmock gtest gtest_main PROPERTIES
CXX_CLANG_TIDY ""
CXX_INCLUDE_WHAT_YOU_USE ""
EXCLUDE_FROM_ALL 1)
#set_target_properties(gmock_main gmock gtest gtest_main PROPERTIES
#CXX_CLANG_TIDY ""
#CXX_INCLUDE_WHAT_YOU_USE ""
#EXCLUDE_FROM_ALL 1)
# loop over all test cases and add them to the test runner
list(LENGTH test_cases len_test_cases)
......@@ -41,7 +41,7 @@ math(EXPR len_test_cases "${len_test_cases} - 1")
foreach (i RANGE "${len_test_cases}")
list(GET test_cases ${i} test_case_name)
add_executable(${test_case_name} ${test_case_name}.cpp)
target_link_libraries(${test_case_name} PRIVATE gtest_main caosdb)
target_link_libraries(${test_case_name} PRIVATE caosdb ${CONAN_LIBS_GTEST} ${CONAN_LIBS_BOOST})
set_target_properties(${test_case_name} PROPERTIES CXX_CLANG_TIDY "")
gtest_discover_tests(${test_case_name}
PROPERTIES
......@@ -58,7 +58,7 @@ if (LCOV_PATH)
NAME unit_test_coverage
EXECUTABLE ctest -L caosdb-cpplib-unit-tests
EXCLUDE "${CMAKE_BINARY_DIR}/*"
DEPEDENCIES caosdb ${test_cases} gtest_main
DEPENDENCIES caosdb ${test_cases}
LCOV_ARGS --rc lcov_branch_coverage=1 --no-external
GENHTML_ARGS --rc lcov_branch_coverage=1
)
......
cmake_minimum_required(VERSION 3.1)
project(PackageTest CXX)
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
add_executable(example example.cpp)
target_link_libraries(example ${CONAN_LIBS})
# CTest is a testing tool that can be used to test your project.
# enable_testing()
# add_test(NAME example
# WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/bin
# COMMAND example)
import os
from conans import ConanFile, CMake, tools
class LibcaosdbTestConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake"
def build(self):
cmake = CMake(self)
# Current dir is "test_package/build/<build_id>" and CMakeLists.txt is
# in "test_package"
cmake.configure()
cmake.build()
def imports(self):
self.copy("*.dll", dst="bin", src="bin")
self.copy("*.dylib*", dst="bin", src="lib")
self.copy('*.so*', dst='bin', src='lib')
def test(self):
if not tools.cross_building(self):
os.chdir("bin")
self.run(".%sexample" % os.sep)
#include "hello.h"
int main() {
hello();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment