diff --git a/.docker/Dockerfile b/.docker/Dockerfile index 3d14869a51254d6bf36446d9cc15d6aff23c773b..991ef2afbfcbef43f2da9149cd3ec6f4f5b9ab04 100644 --- a/.docker/Dockerfile +++ b/.docker/Dockerfile @@ -39,3 +39,7 @@ RUN make -j RUN make install RUN apt-get install -y curl + +COPY . /libcaosdb/ +WORKDIR /libcaosdb +RUN rm -rf .git diff --git a/CMakeLists.txt b/CMakeLists.txt index 287c2580dd1edfcb380829a2b2d4ce49a3f1f717..6d120dba3f3e58562ac030b945bf73f3552ad1b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,6 +82,65 @@ if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") endif() +## 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) + +# Generated sources +set(hw_hdrs_path "caosdb/info/v1alpha1") +set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.pb.cc") +set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/${hw_hdrs_path}/main.pb.h") +set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.grpc.pb.cc") +set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/${hw_hdrs_path}/main.grpc.pb.h") +add_custom_command( + OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/include" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/include" + -I "${PROTO_PATH}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${PROTO_FILES}" + DEPENDS "${PROTO_FILES}") + + + +# hw_grpc_proto +add_library(caosdb_info_v1alpha1 + ${hw_grpc_srcs} + ${hw_grpc_hdrs} + ${hw_proto_srcs} + ${hw_proto_hdrs}) +target_link_libraries(caosdb_info_v1alpha1 + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF}) +target_include_directories(caosdb_info_v1alpha1 PUBLIC + # headers to include when building from source + $<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include> + $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> + $<INSTALL_INTERFACE:include> + ) + +target_link_libraries(caosdb +caosdb_info_v1alpha1 +${_REFLECTION} +${_GRPC_GRPCPP} +${_PROTOBUF_LIBPROTOBUF}) + + +############################################### +############ INSTALLATION ##################### +############################################### + # These variables slightly modify the install location to allow for version # specific installations. set(libcaosdb_INCLUDE_DEST "include/libcaosdb-${libcaosdb_VERSION}") @@ -108,7 +167,7 @@ target_include_directories(caosdb PUBLIC $<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include> # headers to include when installing (implicitly prefixes with ${CMAKE_INSTALL_PREFIX}). - $<INSTALL_INTERFACE:include> + $<INSTALL_INTERFACE:include> ) @@ -131,14 +190,19 @@ set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/libcaosdb/") # libcaosdb with libcaosdbTargets. install( # targets to install - TARGETS caosdb + TARGETS + caosdb + caosdb_info_v1alpha1 + #${_REFLECTION} + #${_GRPC_GRPCPP} + #${_PROTOBUF_LIBPROTOBUF} # name of the CMake "export group" containing the targets we want to install - #EXPORT libcaosdbTargets + EXPORT caosdbTargets # Dynamic, static library and include destination locations after running # "make install" LIBRARY DESTINATION ${libcaosdb_LIB_DEST} ARCHIVE DESTINATION ${libcaosdb_LIB_DEST} - #INCLUDES DESTINATION ${libcaosdb_INCLUDE_DEST} + INCLUDES DESTINATION ${libcaosdb_INCLUDE_DEST} ) @@ -152,72 +216,26 @@ install( # install(EXPORT ...) will install the information about an export. Here, we # save it to a file {$libcaosdb_LIB_DEST}/libcaosdbTargets.cmake and prepend # everything inside libcaosdbTargets with the namespace libcaosdb::. -#install( - ## The export we want to save (matches name defined above containing the - ## install targets) - #EXPORT libcaosdbTargets - ## CMake file in which to store the export's information - #FILE libcaosdbTargets.cmake - ## Namespace prepends all targets in the export (when we import later, we - ## will use caosdb::caosdb) - #NAMESPACE caosdb:: - ## where to place the resulting file (here, we're putting it with the library) - #DESTINATION ${libcaosdb_LIB_DEST} - #) +install( + # The export we want to save (matches name defined above containing the + # install targets) + EXPORT caosdbTargets + # CMake file in which to store the export's information + FILE caosdbTargets.cmake + # Namespace prepends all targets in the export (when we import later, we + # will use caosdb::caosdb) + NAMESPACE caosdb:: + # where to place the resulting file (here, we're putting it with the library) + DESTINATION ${libcaosdb_LIB_DEST} + ) ## 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_INC} DESTINATION ${libcaosdb_INCLUDE_DEST}) - - - -## CODE GENERATION -option(GRPC_FETCHCONTENT "Fetch and build GRPC from the sources" ON) -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) - -# Generated sources -set(hw_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.pb.cc") -set(hw_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.pb.h") -set(hw_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.grpc.pb.cc") -set(hw_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/info/v1alpha1/main.grpc.pb.h") -add_custom_command( - OUTPUT "${hw_proto_srcs}" "${hw_proto_hdrs}" "${hw_grpc_srcs}" "${hw_grpc_hdrs}" - COMMAND ${_PROTOBUF_PROTOC} - ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}/include" - --cpp_out "${CMAKE_CURRENT_BINARY_DIR}/include" - -I "${PROTO_PATH}" - --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" - "${PROTO_FILES}" - DEPENDS "${PROTO_FILES}") - - +install(FILES ${libcaosdb_INCL} DESTINATION ${libcaosdb_INCLUDE_DEST}) +install(FILES ${hw_grpc_hdrs} ${hw_proto_hdrs} + DESTINATION ${libcaosdb_INCLUDE_DEST}/${hw_hdrs_path}) +install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake + DESTINATION ${libcaosdb_LIB_DEST}) -# Include generated *.pb.h files -target_include_directories(caosdb PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include") -# hw_grpc_proto -add_library(caosdb_info_v1alpha1 - ${hw_grpc_srcs} - ${hw_grpc_hdrs} - ${hw_proto_srcs} - ${hw_proto_hdrs}) -target_link_libraries(caosdb_info_v1alpha1 - ${_REFLECTION} - ${_GRPC_GRPCPP} - ${_PROTOBUF_LIBPROTOBUF}) -target_include_directories(caosdb_info_v1alpha1 PUBLIC "${CMAKE_CURRENT_BINARY_DIR}/include") -target_link_libraries(caosdb -caosdb_info_v1alpha1 -${_REFLECTION} -${_GRPC_GRPCPP} -${_PROTOBUF_LIBPROTOBUF}) diff --git a/caosdbConfig.cmake b/caosdbConfig.cmake new file mode 100644 index 0000000000000000000000000000000000000000..cda14607fd77666effc0409fef2d08d3cb6e1daf --- /dev/null +++ b/caosdbConfig.cmake @@ -0,0 +1,10 @@ +get_filename_component(CAOSDB_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) + +include(CMakeFindDependencyMacro) + +find_dependency(Protobuf CONFIG REQUIRED) +find_dependency(gRPC CONFIG REQUIRED) + +if(NOT TARGET caosdb::caosdb) + include("${CAOSDB_CMAKE_DIR}/caosdbTargets.cmake") +endif() diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 8c59e885acdd1a9226541b6ca2874dd2f0acfb0f..47e9f53ca52d4d49c3a94e69709703e0abdf4182 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -20,8 +20,8 @@ # add all header files to this list set(libcaosdb_INCL - include/caosdb_config.h - include/connection.h + ${CMAKE_CURRENT_BINARY_DIR}/caosdb_config.h + ${CMAKE_CURRENT_SOURCE_DIR}/connection.h ) # pass variable to parent scope