Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
caosdb-cpplib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
caosdb
Software
caosdb-cpplib
Commits
c168bec6
Commit
c168bec6
authored
9 months ago
by
Joscha Schmiedt
Browse files
Options
Downloads
Patches
Plain Diff
WIP: get call to protoc running
parent
3df261b1
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!61
Release 0.3.0
,
!53
Add vcpkg support
Pipeline
#53854
failed
9 months ago
Stage: info
Stage: setup
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CMakeLists.txt
+340
-310
340 additions, 310 deletions
CMakeLists.txt
with
340 additions
and
310 deletions
CMakeLists.txt
+
340
−
310
View file @
c168bec6
...
...
@@ -86,70 +86,86 @@ add_subdirectory(doc)
# TODO: Replace this with the protobuf_generate_cpp function
# Protobuf/Grpc source files
set
(
PROTO_FILES
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/info/v1/main.proto
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/entity/v1/main.proto
)
IF
(
BUILD_ACM
)
list
(
APPEND PROTO_FILES
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/acm/v1alpha1/main.proto
)
ENDIF
()
set
(
PROTO_PATH
${
PROJECT_SOURCE_DIR
}
/proto/proto
)
find_package
(
protobuf REQUIRED
)
include_directories
(
${
Protobuf_INCLUDE_DIRS
}
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
)
# protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_FILES})
protobuf_generate_cpp
(
PROTO_SRCS PROTO_HDRS
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/info/v1/main.proto
)
protobuf_generate_cpp
(
PROTO_SRCS PROTO_HDRS
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/entity/v1/main.proto
)
message
(
STATUS
"PROTO_FILES:
${
PROTO_FILES
}
"
)
message
(
STATUS
"PROTO_SRCS:
${
PROTO_SRCS
}
"
)
message
(
STATUS
"PROTO_HDRS:
${
PROTO_HDRS
}
"
)
# set(PROTO_PATH ${PROJECT_SOURCE_DIR}/proto/proto)
# compiler binaries
IF
(
WIN32
)
set
(
_PROTOBUF_PROTOC
"
${
CMAKE_BINARY_DIR
}
/build_tools/protoc.exe"
)
set
(
_GRPC_CPP_PLUGIN_EXECUTABLE
"
${
CMAKE_BINARY_DIR
}
/build_tools/grpc_cpp_plugin.exe"
)
ELSE
()
set
(
_PROTOBUF_PROTOC
"
${
CMAKE_BINARY_DIR
}
/build_tools/protoc"
)
set
(
_GRPC_CPP_PLUGIN_EXECUTABLE
"
${
CMAKE_BINARY_DIR
}
/build_tools/grpc_cpp_plugin"
)
ENDIF
()
# Generated sources
list
(
LENGTH PROTO_FILES len_proto_files
)
math
(
EXPR len_proto_files
"
${
len_proto_files
}
- 1"
)
foreach
(
i RANGE
"
${
len_proto_files
}
"
)
list
(
GET PROTO_FILES
${
i
}
next_proto_file
)
# strip away the prefix path and the ".proto" suffix
string
(
REPLACE
"
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/"
""
next_proto_module
"
${
next_proto_file
}
"
)
string
(
REPLACE
".proto"
""
next_proto_module
"
${
next_proto_module
}
"
)
set
(
next_proto_src
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
.pb.cc"
)
set
(
next_proto_hdr
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
.pb.h"
)
set
(
next_grpc_src
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
.grpc.pb.cc"
)
set
(
next_grpc_hdr
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
.grpc.pb.h"
)
list
(
APPEND GRPC_GENERATED_HEADERS
"
${
next_proto_hdr
}
"
"
${
next_grpc_hdr
}
"
)
list
(
APPEND GRPC_GENERATED_SOURCES
"
${
next_proto_src
}
"
"
${
next_grpc_src
}
"
)
endforeach
()
set
(
GRPC_GENERATED
${
GRPC_GENERATED_SOURCES
}
${
GRPC_GENERATED_HEADERS
}
)
add_custom_command
(
OUTPUT
${
GRPC_GENERATED
}
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
}
)
# IF (WIN32)
# set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc.exe")
# set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin.exe")
# ELSE()
# set(_PROTOBUF_PROTOC "${CMAKE_BINARY_DIR}/build_tools/protoc")
# set(_GRPC_CPP_PLUGIN_EXECUTABLE "${CMAKE_BINARY_DIR}/build_tools/grpc_cpp_plugin")
# ENDIF()
# # Generated sources
# list(LENGTH PROTO_FILES len_proto_files)
# math(EXPR len_proto_files "${len_proto_files} - 1")
# foreach(i RANGE "${len_proto_files}")
# list(GET PROTO_FILES ${i} next_proto_file)
# # strip away the prefix path and the ".proto" suffix
# string(REPLACE
# "${PROJECT_SOURCE_DIR}/proto/proto/caosdb/"
# ""
# next_proto_module
# "${next_proto_file}")
# string(REPLACE
# ".proto"
# ""
# next_proto_module
# "${next_proto_module}")
# set(next_proto_src
# "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}.pb.cc")
# set(next_proto_hdr
# "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}.pb.h")
# set(next_grpc_src
# "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}.grpc.pb.cc")
# set(next_grpc_hdr
# "${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}.grpc.pb.h")
# list(APPEND GRPC_GENERATED_HEADERS "${next_proto_hdr}" "${next_grpc_hdr}")
# list(APPEND GRPC_GENERATED_SOURCES "${next_proto_src}" "${next_grpc_src}")
# endforeach()
# set(GRPC_GENERATED
# ${GRPC_GENERATED_SOURCES}
# ${GRPC_GENERATED_HEADERS})
# add_custom_command(
# OUTPUT ${GRPC_GENERATED}
# 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})
# show generated files
message
(
DEBUG
"GRPC_GENERATED:
${
GRPC_GENERATED
}
"
)
...
...
@@ -165,10 +181,24 @@ message(DEBUG "GRPC_GENERATED: ${GRPC_GENERATED}")
###############################################################################
find_package
(
gRPC CONFIG REQUIRED
)
find_package
(
Protobuf CONFIG REQUIRED
)
find_package
(
Boost REQUIRED
)
# find_package(protobuf CONFIG REQUIRED)
# boost
find_package
(
boost_smart_ptr CONFIG REQUIRED
)
find_package
(
boost_filesystem CONFIG REQUIRED
)
find_package
(
boost_json CONFIG REQUIRED
)
find_package
(
boost_log CONFIG REQUIRED
)
find_package
(
boost_thread CONFIG REQUIRED
)
find_package
(
boost_beast CONFIG REQUIRED
)
find_package
(
GTest REQUIRED
)
set
(
dependencies
gRPC::gpr gRPC::grpc gRPC::grpc++ protobuf::libprotoc protobuf::libprotobuf
Boost::beast Boost::smart_ptr Boost::filesystem Boost::json Boost::log Boost::thread
)
# print include directories for debugging
message
(
DEBUG
"CMAKE_INCLUDE_PATH:
${
CMAKE_INCLUDE_PATH
}
"
)
message
(
DEBUG
"PROTOBUF_INCLUDE_DIRS:
${
PROTOBUF_INCLUDE_DIRS
}
"
)
...
...
@@ -202,7 +232,7 @@ else()
add_library
(
caosdb
SHARED
${
libcaosdb_INCL
}
${
libcaosdb_SRC
}
${
GRPC_GENERATED
}
)
target_link_libraries
(
caosdb
grpc::grpc protobuf::protobuf boost::boost
${
dependencies
}
stdc++fs
)
set
(
LIBCAOSDB caosdb
)
...
...
@@ -219,54 +249,54 @@ target_include_directories(caosdb PUBLIC
# libccaosdb
# ----------
add_library
(
ccaosdb SHARED src/ccaosdb.cpp
)
target_link_libraries
(
ccaosdb
grpc::grpc protobuf::protobuf boost::boost
${
LIBCAOSDB
}
stdc++fs
)
target_include_directories
(
ccaosdb PUBLIC
$<BUILD_INTERFACE:
${
libcaosdb_SOURCE_DIR
}
/include>
$<BUILD_INTERFACE:
${
libcaosdb_BINARY_DIR
}
/include>
$<INSTALL_INTERFACE:include>
)
# ccaosdbcli
# ----------
add_executable
(
ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c
)
target_include_directories
(
ccaosdbcli PUBLIC
$<BUILD_INTERFACE:
${
libcaosdb_SOURCE_DIR
}
/include>
$<BUILD_INTERFACE:
${
libcaosdb_BINARY_DIR
}
/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories
(
ccaosdbcli SYSTEM PUBLIC
${
CONAN_INCLUDE_DIRS
}
)
target_link_libraries
(
ccaosdbcli
grpc::grpc protobuf::protobuf boost::boost
${
LIBCAOSDB
}
ccaosdb
)
# cxxcaosdbcli
# ------------
add_executable
(
cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp
)
target_include_directories
(
cxxcaosdbcli PUBLIC
$<BUILD_INTERFACE:
${
libcaosdb_SOURCE_DIR
}
/include>
$<BUILD_INTERFACE:
${
libcaosdb_BINARY_DIR
}
/include>
$<INSTALL_INTERFACE:include>
)
target_include_directories
(
cxxcaosdbcli SYSTEM PUBLIC
${
CONAN_INCLUDE_DIRS
}
)
target_link_libraries
(
cxxcaosdbcli
${
LIBCAOSDB
}
grpc::grpc protobuf::protobuf boost::boost
)
#
# libccaosdb
#
# ----------
#
add_library(ccaosdb SHARED src/ccaosdb.cpp)
#
target_link_libraries(ccaosdb
#
dependencies
#
${LIBCAOSDB}
#
stdc++fs
#
)
#
target_include_directories(ccaosdb PUBLIC
#
$<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
#
$<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
#
$<INSTALL_INTERFACE:include>
#
)
#
# ccaosdbcli
#
# ----------
#
add_executable(ccaosdbcli EXCLUDE_FROM_ALL src/ccaosdbcli.c)
#
target_include_directories(ccaosdbcli PUBLIC
#
$<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
#
$<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
#
$<INSTALL_INTERFACE:include>
#
)
#
target_include_directories(ccaosdbcli SYSTEM PUBLIC
#
${CONAN_INCLUDE_DIRS}
#
)
#
target_link_libraries(ccaosdbcli
#
dependencies
#
${LIBCAOSDB}
#
ccaosdb
#
)
#
# cxxcaosdbcli
#
# ------------
#
add_executable(cxxcaosdbcli EXCLUDE_FROM_ALL src/cxxcaosdbcli.cpp)
#
target_include_directories(cxxcaosdbcli PUBLIC
#
$<BUILD_INTERFACE:${libcaosdb_SOURCE_DIR}/include>
#
$<BUILD_INTERFACE:${libcaosdb_BINARY_DIR}/include>
#
$<INSTALL_INTERFACE:include>
#
)
#
target_include_directories(cxxcaosdbcli SYSTEM PUBLIC
#
${CONAN_INCLUDE_DIRS}
#
)
#
target_link_libraries(cxxcaosdbcli
#
${LIBCAOSDB}
#
dependencies
#
)
...
...
@@ -274,213 +304,213 @@ target_link_libraries(cxxcaosdbcli
### LINTING with CLANG-TIDY and INCLUDE-WHAT-YOU-USE
#######################################################
include
(
CheckCXXCompilerFlag
)
include
(
CheckCCompilerFlag
)
function
(
add_compiler_flag flag
)
string
(
FIND
"
${
CMAKE_CXX_FLAGS
}
"
"
${
flag
}
"
cxx_present
)
if
(
cxx_present EQUAL -1
)
check_cxx_compiler_flag
(
"
${
flag
}
"
flag_supported
)
if
(
flag_supported
)
set
(
PEDANTIC_CMAKE_CXX_FLAGS
"
${
PEDANTIC_CMAKE_CXX_FLAGS
}
${
flag
}
"
PARENT_SCOPE
)
endif
()
unset
(
flag_supported CACHE
)
endif
()
unset
(
cxx_present CACHE
)
string
(
FIND
"
${
CMAKE_C_FLAGS
}
"
"
${
flag
}
"
c_present
)
if
(
c_present EQUAL -1
)
check_cxx_compiler_flag
(
"
${
flag
}
"
flag_supported
)
if
(
flag_supported
)
set
(
PEDANTIC_CMAKE_C_FLAGS
"
${
PEDANTIC_CMAKE_C_FLAGS
}
${
flag
}
"
PARENT_SCOPE
)
endif
()
unset
(
flag_supported CACHE
)
endif
()
unset
(
c_present CACHE
)
endfunction
()
option
(
LINTING
"Enable linting with clang-tidy and iwyu when in non-Debug build-type"
OFF
)
if
(
"
${
CMAKE_BUILD_TYPE
}
"
MATCHES
"Debug"
OR LINTING
)
set
(
_LINTING ON
)
endif
()
option
(
SKIP_LINTING
"Skip linting even when in Debug build-type"
OFF
)
if
(
"
${
CMAKE_BUILD_TYPE
}
"
MATCHES
"Debug"
AND SKIP_LINTING
)
message
(
WARNING
"Skipping linting due to SKIP_LINTING option"
)
set
(
_LINTING OFF
)
endif
()
if
(
_LINTING
)
### set paranoid compiler flags
add_compiler_flag
(
"-Wall"
)
add_compiler_flag
(
"-Wextra"
)
add_compiler_flag
(
"-pedantic"
)
# add_compiler_flag("-Werror") # removed until issue #71 is resolved
message
(
STATUS
"PEDANTIC_CMAKE_CXX_FLAGS: [
${
PEDANTIC_CMAKE_CXX_FLAGS
}
]"
)
set
(
TARGET_CAOSDB_COMPILE_FLAGS
"
${
TARGET_CAOSDB_COMPILE_FLAGS
}
${
PEDANTIC_CMAKE_CXX_FLAGS
}
"
)
set
(
TARGET_CCAOSDB_COMPILE_FLAGS
"
${
TARGET_CCAOSDB_COMPILE_FLAGS
}
${
PEDANTIC_CMAKE_C_FLAGS
}
"
)
set
(
TARGET_CXXCAOSDBCLI_COMPILE_FLAGS
"
${
TARGET_CXXCAOSDBCLI_COMPILE_FLAGS
}
${
PEDANTIC_CMAKE_CXX_FLAGS
}
"
)
set
(
TARGET_CCAOSDBCLI_COMPILE_FLAGS
"
${
TARGET_CCAOSDBCLI_COMPILE_FLAGS
}
${
PEDANTIC_CMAKE_C_FLAGS
}
"
)
set_target_properties
(
caosdb PROPERTIES
COMPILE_FLAGS
"
${
TARGET_CAOSDB_COMPILE_FLAGS
}
"
)
set_target_properties
(
ccaosdb PROPERTIES
COMPILE_FLAGS
"
${
TARGET_CCAOSDB_COMPILE_FLAGS
}
"
)
set_target_properties
(
cxxcaosdbcli PROPERTIES
COMPILE_FLAGS
"
${
TARGET_CXXCAOSDBCLI_COMPILE_FLAGS
}
"
)
set_target_properties
(
ccaosdbcli PROPERTIES
COMPILE_FLAGS
"
${
TARGET_CCAOSDBCLI_COMPILE_FLAGS
}
"
)
find_program
(
iwyu
NAMES include-what-you-use iwyu
PATHS
${
CMAKE_SOURCE_DIR
}
/tools/include-what-you-use/
${
iwyu_os
}
/bin
)
if
(
NOT iwyu
)
message
(
WARNING
"include-what-you-use: Not found"
)
else
()
message
(
STATUS
"include-what-you-use:
${
iwyu
}
"
)
set
(
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
${
iwyu
}
"-Xiwyu"
"--cxx17ns"
"-Xiwyu"
"--no_fwd_decls"
)
set_target_properties
(
caosdb PROPERTIES
CXX_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
set_target_properties
(
cxxcaosdbcli PROPERTIES
CXX_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
set_target_properties
(
ccaosdbcli PROPERTIES
C_INCLUDE_WHAT_YOU_USE
"
${
_CMAKE_CXX_INCLUDE_WHAT_YOU_USE
}
"
)
endif
()
find_program
(
clang_tidy NAMES clang-tidy clang-tidy-11
)
if
(
NOT clang_tidy
)
message
(
WARNING
"clang-tidy: Not found"
)
else
()
message
(
STATUS
"clang-tidy:
${
clang_tidy
}
"
)
set
(
_CMAKE_CXX_CLANG_TIDY_CHECKS
"--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-misc-include-cleaner,-readability-identifier-*,-llvm-include-order,-misc-const-correctness"
)
set
(
_CMAKE_C_CLANG_TIDY_CHECKS
"
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
)
set
(
_CMAKE_CXX_CLANG_TIDY
"
${
clang_tidy
}
"
"--header-filter=caosdb/.*[^
\(
\.pb\.h
\)
]$"
)
# "--warnings-as-errors=*")
set
(
_CMAKE_C_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
"
)
option
(
AUTO_FIX_LINTING
"Append --fix option to clang-tidy"
OFF
)
if
(
AUTO_FIX_LINTING
)
set
(
_CMAKE_CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;--fix"
)
endif
()
message
(
STATUS
"Using clang-tidy with
'
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
'"
)
set_target_properties
(
caosdb PROPERTIES
CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
)
set_target_properties
(
cxxcaosdbcli PROPERTIES
CXX_CLANG_TIDY
"
${
_CMAKE_CXX_CLANG_TIDY
}
;
${
_CMAKE_CXX_CLANG_TIDY_CHECKS
}
"
)
set_target_properties
(
ccaosdb PROPERTIES
C_CLANG_TIDY
"
${
_CMAKE_C_CLANG_TIDY
}
;
${
_CMAKE_C_CLANG_TIDY_CHECKS
}
"
)
set_target_properties
(
ccaosdbcli PROPERTIES
C_CLANG_TIDY
"
${
_CMAKE_C_CLANG_TIDY
}
;
${
_CMAKE_C_CLANG_TIDY_CHECKS
}
"
)
endif
()
endif
()
#######################################################
### UNIT TEST
#######################################################
if
(
"
${
CMAKE_BUILD_TYPE
}
"
MATCHES
"Debug"
)
enable_testing
()
add_subdirectory
(
test
)
endif
()
# ###############################################
# ############ INSTALLATION #####################
# ###############################################
set
(
libcaosdb_INCLUDE_DEST
"include/caosdb"
)
set
(
libcaosdb_LIB_DEST
"lib"
)
set
(
CMAKE_INSTALL_PREFIX
"$ENV{HOME}/.local/"
)
install
(
# targets to install
TARGETS
${
LIBCAOSDB
}
ccaosdb
# name of the CMake "export group" containing the targets we want to install
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
}
)
set
(
libcaosdb_CMAKE_DEST
"
${
libcaosdb_LIB_DEST
}
/cmake/caosdb"
)
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_CMAKE_DEST
}
)
install
(
FILES
${
libcaosdb_INCL
}
${
PROJECT_SOURCE_DIR
}
/include/ccaosdb.h DESTINATION
${
libcaosdb_INCLUDE_DEST
}
)
foreach
(
i RANGE
"
${
len_proto_files
}
"
)
list
(
GET PROTO_FILES
${
i
}
next_proto_file
)
# strip away the prefix path and the ".proto" suffix
string
(
REPLACE
"
${
PROJECT_SOURCE_DIR
}
/proto/proto/caosdb/"
""
next_proto_module
"
${
next_proto_file
}
"
)
string
(
REPLACE
"/main.proto"
""
next_proto_module
"
${
next_proto_module
}
"
)
set
(
next_proto_hdr
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
/main.pb.h"
)
set
(
next_grpc_hdr
"
${
CMAKE_CURRENT_BINARY_DIR
}
/include/caosdb/
${
next_proto_module
}
/main.grpc.pb.h"
)
install
(
FILES
${
next_proto_hdr
}
${
next_grpc_hdr
}
DESTINATION
${
libcaosdb_INCLUDE_DEST
}
/
${
next_proto_module
}
)
endforeach
()
install
(
FILES
${
PROJECT_SOURCE_DIR
}
/caosdbConfig.cmake
DESTINATION
${
libcaosdb_CMAKE_DEST
}
)
#set_property(TARGET caosdb PROPERTY VERSION ${libcaosdb_VERSION})
include
(
CMakePackageConfigHelpers
)
write_basic_package_version_file
(
"
${
PROJECT_SOURCE_DIR
}
/caosdbConfigVersion.cmake"
VERSION
${
libcaosdb_VERSION
}
COMPATIBILITY AnyNewerVersion
)
install
(
FILES
${
PROJECT_SOURCE_DIR
}
/caosdbConfigVersion.cmake
DESTINATION
${
libcaosdb_CMAKE_DEST
}
)
#######################################################
### code formatting with clang-format
#######################################################
option
(
AUTOFORMATTING
"call clang-format at configure time"
ON
)
if
(
AUTOFORMATTING AND NOT SKIP_LINTING
)
find_program
(
clang_format NAMES clang-format-11 clang-format
)
file
(
GLOB format_test_sources test/*.cpp test/*.h test/*.h.in
)
execute_process
(
COMMAND
${
clang_format
}
-i --verbose
${
libcaosdb_INCL
}
${
libcaosdb_SRC
}
${
libcaosdb_TEST_SRC
}
${
PROJECT_SOURCE_DIR
}
/src/cxxcaosdbcli.cpp
${
PROJECT_SOURCE_DIR
}
/src/ccaosdbcli.c
${
PROJECT_SOURCE_DIR
}
/src/ccaosdb.cpp
${
PROJECT_SOURCE_DIR
}
/include/ccaosdb.h
${
format_test_sources
}
WORKING_DIRECTORY
${
PROJECT_SOURCE_DIR
}
)
endif
()
#
include(CheckCXXCompilerFlag)
#
include(CheckCCompilerFlag)
#
function(add_compiler_flag flag)
#
string(FIND "${CMAKE_CXX_FLAGS}" "${flag}" cxx_present)
#
if(cxx_present EQUAL -1)
#
check_cxx_compiler_flag("${flag}" flag_supported)
#
if(flag_supported)
#
set(PEDANTIC_CMAKE_CXX_FLAGS "${PEDANTIC_CMAKE_CXX_FLAGS} ${flag}" PARENT_SCOPE)
#
endif()
#
unset(flag_supported CACHE)
#
endif()
#
unset(cxx_present CACHE)
#
string(FIND "${CMAKE_C_FLAGS}" "${flag}" c_present)
#
if(c_present EQUAL -1)
#
check_cxx_compiler_flag("${flag}" flag_supported)
#
if(flag_supported)
#
set(PEDANTIC_CMAKE_C_FLAGS "${PEDANTIC_CMAKE_C_FLAGS} ${flag}" PARENT_SCOPE)
#
endif()
#
unset(flag_supported CACHE)
#
endif()
#
unset(c_present CACHE)
#
endfunction()
#
option(LINTING "Enable linting with clang-tidy and iwyu when in non-Debug build-type" OFF)
#
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" OR LINTING)
#
set(_LINTING ON)
#
endif()
#
option(SKIP_LINTING "Skip linting even when in Debug build-type" OFF)
#
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug" AND SKIP_LINTING)
#
message(WARNING "Skipping linting due to SKIP_LINTING option")
#
set(_LINTING OFF)
#
endif()
#
if(_LINTING)
#
### set paranoid compiler flags
#
add_compiler_flag("-Wall")
#
add_compiler_flag("-Wextra")
#
add_compiler_flag("-pedantic")
#
# add_compiler_flag("-Werror") # removed until issue #71 is resolved
#
message(STATUS "PEDANTIC_CMAKE_CXX_FLAGS: [${PEDANTIC_CMAKE_CXX_FLAGS}]")
#
set(TARGET_CAOSDB_COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}")
#
set(TARGET_CCAOSDB_COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}")
#
set(TARGET_CXXCAOSDBCLI_COMPILE_FLAGS "${TARGET_CXXCAOSDBCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_CXX_FLAGS}")
#
set(TARGET_CCAOSDBCLI_COMPILE_FLAGS "${TARGET_CCAOSDBCLI_COMPILE_FLAGS} ${PEDANTIC_CMAKE_C_FLAGS}")
#
set_target_properties(caosdb PROPERTIES
#
COMPILE_FLAGS "${TARGET_CAOSDB_COMPILE_FLAGS}")
#
set_target_properties(ccaosdb PROPERTIES
#
COMPILE_FLAGS "${TARGET_CCAOSDB_COMPILE_FLAGS}")
#
set_target_properties(cxxcaosdbcli PROPERTIES
#
COMPILE_FLAGS "${TARGET_CXXCAOSDBCLI_COMPILE_FLAGS}")
#
set_target_properties(ccaosdbcli PROPERTIES
#
COMPILE_FLAGS "${TARGET_CCAOSDBCLI_COMPILE_FLAGS}")
#
find_program(iwyu
#
NAMES include-what-you-use iwyu
#
PATHS ${CMAKE_SOURCE_DIR}/tools/include-what-you-use/${iwyu_os}/bin)
#
if(NOT iwyu)
#
message(WARNING "include-what-you-use: Not found")
#
else()
#
message(STATUS "include-what-you-use: ${iwyu}")
#
set(_CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${iwyu}
#
"-Xiwyu" "--cxx17ns" "-Xiwyu" "--no_fwd_decls")
#
set_target_properties(caosdb PROPERTIES
#
CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
#
)
#
set_target_properties(cxxcaosdbcli PROPERTIES
#
CXX_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
#
)
#
set_target_properties(ccaosdbcli PROPERTIES
#
C_INCLUDE_WHAT_YOU_USE "${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE}"
#
)
#
endif()
#
find_program(clang_tidy NAMES clang-tidy clang-tidy-11)
#
if(NOT clang_tidy)
#
message(WARNING "clang-tidy: Not found")
#
else()
#
message(STATUS "clang-tidy: ${clang_tidy}")
#
set(_CMAKE_CXX_CLANG_TIDY_CHECKS
#
"--checks=*,-fuchsia-*,-llvmlibc-*,-readability-convert-member-functions-to-static,-cppcoreguidelines-pro-bounds-array-to-pointer-decay,-hicpp-no-array-decay,-llvm-else-after-return,-readability-else-after-return,-modernize-use-trailing-return-type,-bugprone-branch-clone,-altera-*,-misc-include-cleaner,-readability-identifier-*,-llvm-include-order,-misc-const-correctness")
#
set(_CMAKE_C_CLANG_TIDY_CHECKS "${_CMAKE_CXX_CLANG_TIDY_CHECKS}")
#
set(_CMAKE_CXX_CLANG_TIDY "${clang_tidy}"
#
"--header-filter=caosdb/.*[^\(\.pb\.h\)]$")
#
# "--warnings-as-errors=*")
#
set(_CMAKE_C_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY}")
#
option(AUTO_FIX_LINTING "Append --fix option to clang-tidy" OFF)
#
if(AUTO_FIX_LINTING)
#
set(_CMAKE_CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};--fix")
#
endif()
#
message(STATUS "Using clang-tidy with
#
'${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}'")
#
set_target_properties(caosdb PROPERTIES
#
CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}"
#
)
#
set_target_properties(cxxcaosdbcli PROPERTIES
#
CXX_CLANG_TIDY "${_CMAKE_CXX_CLANG_TIDY};${_CMAKE_CXX_CLANG_TIDY_CHECKS}"
#
)
#
set_target_properties(ccaosdb PROPERTIES
#
C_CLANG_TIDY "${_CMAKE_C_CLANG_TIDY};${_CMAKE_C_CLANG_TIDY_CHECKS}"
#
)
#
set_target_properties(ccaosdbcli PROPERTIES
#
C_CLANG_TIDY "${_CMAKE_C_CLANG_TIDY};${_CMAKE_C_CLANG_TIDY_CHECKS}"
#
)
#
endif()
#
endif()
#
#######################################################
#
### UNIT TEST
#
#######################################################
#
if("${CMAKE_BUILD_TYPE}" MATCHES "Debug")
#
enable_testing()
#
add_subdirectory(test)
#
endif()
#
#
###############################################
#
#
############ INSTALLATION #####################
#
#
###############################################
#
set(libcaosdb_INCLUDE_DEST "include/caosdb")
#
set(libcaosdb_LIB_DEST "lib")
#
set(CMAKE_INSTALL_PREFIX "$ENV{HOME}/.local/")
#
install(
#
# targets to install
#
TARGETS ${LIBCAOSDB} ccaosdb
#
# name of the CMake "export group" containing the targets we want to install
#
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}
#
)
#
set(libcaosdb_CMAKE_DEST "${libcaosdb_LIB_DEST}/cmake/caosdb")
#
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_CMAKE_DEST}
#
)
#
install(FILES ${libcaosdb_INCL} ${PROJECT_SOURCE_DIR}/include/ccaosdb.h DESTINATION ${libcaosdb_INCLUDE_DEST})
#
foreach(i RANGE "${len_proto_files}")
#
list(GET PROTO_FILES ${i} next_proto_file)
#
# strip away the prefix path and the ".proto" suffix
#
string(REPLACE
#
"${PROJECT_SOURCE_DIR}/proto/proto/caosdb/"
#
""
#
next_proto_module
#
"${next_proto_file}")
#
string(REPLACE
#
"/main.proto"
#
""
#
next_proto_module
#
"${next_proto_module}")
#
set(next_proto_hdr
#
"${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.pb.h")
#
set(next_grpc_hdr
#
"${CMAKE_CURRENT_BINARY_DIR}/include/caosdb/${next_proto_module}/main.grpc.pb.h")
#
install(FILES ${next_proto_hdr} ${next_grpc_hdr} DESTINATION
#
${libcaosdb_INCLUDE_DEST}/${next_proto_module})
#
endforeach()
#
install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfig.cmake
#
DESTINATION ${libcaosdb_CMAKE_DEST})
#
#set_property(TARGET caosdb PROPERTY VERSION ${libcaosdb_VERSION})
#
include(CMakePackageConfigHelpers)
#
write_basic_package_version_file(
#
"${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake"
#
VERSION ${libcaosdb_VERSION}
#
COMPATIBILITY AnyNewerVersion
#
)
#
install(FILES ${PROJECT_SOURCE_DIR}/caosdbConfigVersion.cmake
#
DESTINATION ${libcaosdb_CMAKE_DEST})
#
#######################################################
#
### code formatting with clang-format
#
#######################################################
#
option(AUTOFORMATTING "call clang-format at configure time" ON)
#
if(AUTOFORMATTING AND NOT SKIP_LINTING)
#
find_program(clang_format NAMES clang-format-11 clang-format)
#
file(GLOB format_test_sources test/*.cpp test/*.h test/*.h.in)
#
execute_process(COMMAND ${clang_format} -i --verbose ${libcaosdb_INCL}
#
${libcaosdb_SRC} ${libcaosdb_TEST_SRC}
#
${PROJECT_SOURCE_DIR}/src/cxxcaosdbcli.cpp
#
${PROJECT_SOURCE_DIR}/src/ccaosdbcli.c
#
${PROJECT_SOURCE_DIR}/src/ccaosdb.cpp
#
${PROJECT_SOURCE_DIR}/include/ccaosdb.h
#
${format_test_sources}
#
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
#
endif()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment