Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#
# This file is a part of the CaosDB Project.
#
# Copyright (C) 2021 Timm Fitschen <t.fitschen@indiscale.com>
# Copyright (C) 2021 IndiScale GmbH <info@indiscale.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.15)
project(OctaveCaosDB
DESCRIPTION "GNU/Octave wrapper for libcaosdb, the C++ client library of the CaosDB project."
LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# dependency management with conan
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()
# fix grpc - remove unsecure (no-op ssl implementations)
string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_LIBS_GRPC
"${CONAN_LIBS_GRPC}")
string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS_GRPC
"${CONAN_PKG_LIBS_GRPC}")
string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_LIBS
"${CONAN_LIBS}")
string(REGEX REPLACE ";grpc\\+?\\+?_unsecure" "" CONAN_PKG_LIBS
"${CONAN_PKG_LIBS}")
#######################################################
### code formatting with clang-format
#######################################################
option(AUTOFORMATTING "call clang-format at configure time" ON)
if(AUTOFORMATTING)
file(GLOB format_sources src/*.cpp)
execute_process(COMMAND clang-format -i --verbose ${format_sources}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
endif()
#######################################################
### Compile *.mex files
#######################################################
set(PKG_INST_DIR "${PROJECT_SOURCE_DIR}/inst")
file(MAKE_DIRECTORY ${PKG_INST_DIR})
string(REGEX REPLACE ";" ";-I" _MKOCTFILE_INCLUDES "-I${CONAN_INCLUDE_DIRS}")
string(REGEX REPLACE ";" ";-L" _MKOCTFILE_LIB_DIRS "-L${CONAN_LIB_DIRS}")
string(REGEX REPLACE ";" ";-l" _MKOCTFILE_LIBS "-l${CONAN_LIBS}")
string(REGEX REPLACE ";" ":" _MKOCTFILE_RPATH "${CONAN_LIB_DIRS}")
set(_MKOCTFILE_OPTIONS "-o" "${PKG_INST_DIR}/caosdb.mex" "-Wl,-rpath,${_MKOCTFILE_RPATH}" "--mex" "-std=gnu++17"
"-L/usr/local/lib" ${_MKOCTFILE_INCLUDES} ${_MKOCTFILE_LIB_DIRS} ${_MKOCTFILE_LIBS})
add_custom_command(OUTPUT ${PKG_INST_DIR}/caosdb.mex
ARGS ${_MKOCTFILE_OPTIONS} ${OCTAVE_CAOSDB_SRC}
DEPENDS ${OCTAVE_CAOSDB_SRC}
)
add_custom_target(caosdb.mex ALL
SOURCES ${PKG_INST_DIR}/caosdb.mex)
#######################################################
### Linting with clang-tidy and include-what-you-use
#######################################################
option(LINTING "clang-tidy and iwyu" OFF)
if(LINTING)
execute_process(COMMAND mkoctfile -p OCTINCLUDEDIR
OUTPUT_VARIABLE _OCTINCLUDEDIR
)
string(REGEX REPLACE "\n" "" _OCTINCLUDEDIR "${_OCTINCLUDEDIR}")
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
"--warnings-as-errors=*"
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"--fix")
set(_CMAKE_CXX_CLANG_TIDY_CHECKS
"--checks=*,-fuchsia-*,-llvmlibc-*,-llvm-else-after-return,-readability-else-after-return,-cppcoreguidelines-pro-type-vararg,-hicpp-vararg,-cppcoreguidelines-pro-bounds-pointer-arithmetic,-cert-err58-cpp")
add_custom_command(
TARGET caosdb.mex
COMMAND ${clang_tidy}
ARGS ${_CMAKE_CXX_CLANG_TIDY} ${_CMAKE_CXX_CLANG_TIDY_CHECKS}
${OCTAVE_CAOSDB_SRC} "--" ${_MKOCTFILE_INCLUDES} "-I/usr/include"
"-I${_OCTINCLUDEDIR}" "-std=c++17"
DEPENDS ${OCTAVE_CAOSDB_SRC})
endif()
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
"-Xiwyu" "--no_fwd_decls"
"-Xiwyu" "--cxx17ns")
add_custom_command(
TARGET caosdb.mex
COMMAND ${iwyu}
ARGS ${_CMAKE_CXX_INCLUDE_WHAT_YOU_USE} "-I${_OCTINCLUDEDIR}"
"-std=c++17" "-I/usr/include" ${_MKOCTFILE_INCLUDES}
DEPENDS ${OCTAVE_CAOSDB_SRC})
endif()
else()
message(STATUS "LINTING is OFF")
endif()