diff options
author | YohanPipereau <ypiperea@cisco.com> | 2019-03-12 14:15:26 +0100 |
---|---|---|
committer | Hongjun Ni <hongjun.ni@intel.com> | 2019-03-18 00:51:36 +0000 |
commit | d7680154981c54989bcbcab81173791dc1805512 (patch) | |
tree | 5a1e807c0cb91d478eca43d0f673daa4006fa124 /src/cmake | |
parent | f8118bf32a5e5276f796c3f03095c2ee1a41423a (diff) |
Fix Cmake build environment and harden Warnings
-Remove unused sweetcomb CmakeList.txt Warnings
-Add more Warnings to plugins, scvpp and gNMI Cmake projects
-Remove unused/useless Cmake options in CmakeList files & add comments
-Improve gNMI CMakeList.txt and make it independant of a gRPC cmake build for
later package integration.
-Add FindGRPC.cmake
-Remove the use of CXX17 variant and use a dedicated Cmake module for
gRPC
Change-Id: Iafa3c031d12802e8d8c914cbce6b119c2a5c4800
Signed-off-by: Yohan Pipereau <ypiperea@cisco.com>
Diffstat (limited to 'src/cmake')
-rw-r--r-- | src/cmake/FindGRPC.cmake | 76 | ||||
-rw-r--r-- | src/cmake/FindVPP.cmake | 26 |
2 files changed, 83 insertions, 19 deletions
diff --git a/src/cmake/FindGRPC.cmake b/src/cmake/FindGRPC.cmake new file mode 100644 index 0000000..e45f969 --- /dev/null +++ b/src/cmake/FindGRPC.cmake @@ -0,0 +1,76 @@ +# From https://github.com/wastl/cmarmotta/blob/master/cmake/FindGRPC.cmake +# +# - Try to find gRPC +# Once done this will define +# +# GRPC_CPP_PLUGIN - Absolute path to grpc c++ plugin +# GRPCPP_LIBRARY - +# GPR_LIBRARY - +# +# VPP_FOUND - system has VPP +# VPP_INCLUDE_DIRS - the VPP include directory +# VPP_LIBRARIES - Link these to use LibSSH + +#Absolute path to grpc_cpp_plugin +find_program(GRPC_CPP_PLUGIN grpc_cpp_plugin) + +find_library(GRPC_LIBRARY NAMES grpc) +find_library(GRPCPP_LIBRARY NAMES grpc++) +find_library(GPR_LIBRARY NAMES gpr) +set(GRPC_LIBRARIES ${GRPCPP_LIBRARY} ${GRPC_LIBRARY} ${GPR_LIBRARY}) + +function(PROTOBUF_GENERATE_GRPC_CPP SRCS HDRS) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files") + return() + endif() + + if(PROTOBUF_GENERATE_CPP_APPEND_PATH) # This variable is common for all types of output. + # Create an include path for each file specified + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(ABS_PATH ${ABS_FIL} PATH) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + else() + set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR}) + endif() + + if(DEFINED PROTOBUF_IMPORT_DIRS) + foreach(DIR ${PROTOBUF_IMPORT_DIRS}) + get_filename_component(ABS_PATH ${DIR} ABSOLUTE) + list(FIND _protobuf_include_path ${ABS_PATH} _contains_already) + if(${_contains_already} EQUAL -1) + list(APPEND _protobuf_include_path -I ${ABS_PATH}) + endif() + endforeach() + endif() + + set(${SRCS}) + set(${HDRS}) + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + + list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.cc") + list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.h") + + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.grpc.pb.h" + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} + ARGS --grpc_out=${CMAKE_CURRENT_BINARY_DIR} + --plugin=protoc-gen-grpc=${GRPC_CPP_PLUGIN} + ${_protobuf_include_path} ${ABS_FIL} + DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE} + COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}" + VERBATIM) + endforeach() + + set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE) + set(${SRCS} ${${SRCS}} PARENT_SCOPE) + set(${HDRS} ${${HDRS}} PARENT_SCOPE) +endfunction() diff --git a/src/cmake/FindVPP.cmake b/src/cmake/FindVPP.cmake index 3f229dc..afc1520 100644 --- a/src/cmake/FindVPP.cmake +++ b/src/cmake/FindVPP.cmake @@ -1,11 +1,3 @@ -# - Try to find LibVPP -# Once done this will define -# -# VPP_FOUND - system has VPP -# VPP_INCLUDE_DIRS - the VPP include directory -# VPP_LIBRARIES - Link these to use LibSSH -# - # # Copyright (c) 2018 PANTHEON.tech. # @@ -20,7 +12,14 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. + + +# - Try to find LibVPP +# Once done this will define # +# VPP_FOUND - system has VPP +# VPP_INCLUDE_DIRS - the VPP include directory +# VPP_LIBRARIES - Link these to use LibSSH if (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) @@ -159,16 +158,6 @@ else (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) ${CMAKE_INSTALL_PREFIX}/lib ) -# find_library(VOM_LIBRARY -# NAMES -# vom -# libvom -# PATHS -# ${VPP_LIBRARY_PATH} -# ${CMAKE_LIBRARY_PATH} -# ${CMAKE_INSTALL_PREFIX}/lib -# ) - if (VPP_INCLUDE_DIR AND VPP_LIBRARY) set(VPP_FOUND TRUE) else (VPP_INCLUDE_DIR AND VPP_LIBRARY) @@ -191,7 +180,6 @@ else (VPP_LIBRARIES AND VPP_INCLUDE_DIRS) ${VLIB_LIBRARY} ${VATPLUGIN_LIBRARY} ${VAPI_LIBRARY} -# ${VOM_LIBRARY} ) # show the VPP_INCLUDE_DIRS and VPP_LIBRARIES variables only in the advanced view |