Getting error when vanetza is used in a main project as a subdirectory
Closed this issue · 2 comments
Hi There,
My goal is to create a v2x project and use vanetza in it (add_subdirectory(vanetza-master)). Unfortunately, I am getting error messages, I have been trying to solve this issue almost a week and could not resolve it; I need help. Please help. Thanks in advance.
BTW, I am new in C++ and CMake :)
1. Error messages:
-
vvanetza/security/backend_openssl.cpp: In member function ‘virtual vanetza::security::EcdsaSignature vanetza::security::BackendOpenSsl::sign_data(const vanetza::security::ecdsa256::PrivateKey&, const ByteBuffer&)’:
/home/ekrem/dev/c-v2x/vanetza-master/vanetza/security/backend_openssl.cpp:34:36: error: invalid use of incomplete type ‘ECDSA_SIG’ {aka ‘struct ECDSA_SIG_st’}
const BIGNUM* sig_r = signature->r;In file included from /usr/include/openssl/ecdsa.h:10,
from /home/ekrem/dev/c-v2x/vanetza-master/vanetza/security/openssl_wrapper.hpp:7,
from /home/ekrem/dev/c-v2x/vanetza-master/vanetza/security/backend_openssl.cpp:2:
/usr/include/openssl/ec.h:1125:16: note: forward declaration of ‘ECDSA_SIG’ {aka ‘struct ECDSA_SIG_st’}
typedef struct ECDSA_SIG_st ECDSA_SIG; -
/c-v2x/vanetza-master/vanetza/security/sha.cpp:28:5: error: #error "no SHA256 implementation available"
error "no SHA256 implementation available" -
/c-v2x/vanetza-master/tools/cohda_proxy/proxy_handler.hpp:10:10: fatal error: mk2mac-api-types.h: No such file or directory
#include <mk2mac-api-types.h> -
/c-v2x/vanetza-master/tools/socktap/cohda.cpp:7:10: fatal error: llc-api.h: No such fe or directoryile or directory
#include <llc-api.h> -
/caster/tools/sockt-v2x/vanetza-master/tools/socktap/gps_position_provider.hpp:10:10: fatal error: gps.h: No such file or directory
#include <gps.h>
2. My environment info:
Ubuntu 20.04
gcc: 9.3
openssl: 1.1.1f
libboost: 1.71
3. Project directory structure:
c-v2x
|___ common
|___ test
|___ vantetza-master
|___ CMakeList.txt
|___ main.cpp
4. My main project CMakeList.txt:
`
cmake_minimum_required(VERSION 3.20)
project(c-v2x)
MACRO(HEADER_DIRECTORIES return_list componentName)
FILE(GLOB_RECURSE new_list ${CMAKE_CURRENT_SOURCE_DIR}/${componentName}/**/*[.h.hpp])
set(dir_list "")
FOREACH (file_path ${new_list})
GET_FILENAME_COMPONENT(dir_path ${file_path} PATH)
set(dir_list ${dir_list} ${dir_path})
ENDFOREACH ()
LIST(REMOVE_DUPLICATES dir_list)
set(${return_list} ${dir_list})
ENDMACRO()
HEADER_DIRECTORIES(tools vanetza-master/tools/)
HEADER_DIRECTORIES(vanetzaFolder vanetza-master/vanetza/)
set(CMAKE_CXX_STANDARD 17)
file(GLOB_RECURSE HEADER_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/vanetza-master/**/[.h.hpp]"
"${CMAKE_CURRENT_SOURCE_DIR}/common/[.h.hpp]")
file(GLOB_RECURSE SOURCE_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/vanetza-master/**/[.c.cpp]"
"${CMAKE_CURRENT_SOURCE_DIR}/common/.cpp")
list(FILTER SOURCE_FILES EXCLUDE REGEX "cohda")
list(FILTER SOURCE_FILES EXCLUDE REGEX "socktap")
include_directories(common/ common/Gtest/googletest/include common/Gtest/googlemock/include vanetza-master ${tools} ${vanetzaFolder})
add_subdirectory(vanetza-master)
add_subdirectory(common/Gtest)
find_package(Threads REQUIRED)
set(Boost_INCLUDE_DIR /usr/include)
set(Boost_LIBRARY_DIR /usr/lib/x86_64-linux-gnu)
find_package(Boost COMPONENTS system filesystem REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
add_executable(c-v2x ${SOURCE_FILES} ${HEADER_FILES})
target_link_libraries(c-v2x gtest_main Threads::Threads ${Boost_LIBRARY_DIR}/libpthread.so rt)
target_include_directories(c-v2x
PRIVATE
${tools}
${vanetzaFolder}
)
`
5. Vanetza CMakeList file:
`
set(PROJECT_VERSION 1)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/vanetza-master/cmake)
-- enable convenient CMake policies if available
if(POLICY CMP0074)
-- find_package() employs _ROOT (since CMake 3.12)
cmake_policy(SET CMP0074 NEW)
endif()
if(POLICY CMP0077)
-- option() honours normal variable (since CMake 3.13)
cmake_policy(SET CMP0077 NEW)
endif()
-- Vanetza makes extensive use of C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-- Load conan configuration if available
if(EXISTS ${PROJECT_BINARY_DIR}/cmake-build-debug/conanbuildinfo.cmake)
include(${PROJECT_BINARY_DIR}/cmake-build-debug/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
set(Boost_NO_SYSTEM_PATHS ON)
endif()
-- Look up threading library (usually pthread)
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads MODULE)
-- Build configuration options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_TESTS "Build unit tests" OFF)
if(BUILD_TESTS)
enable_testing()
add_subdirectory(gtest)
endif()
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/cmake-build-debug/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/cmake-build-debug/lib)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/cmake-build-debug/lib/static)
option(VANETZA_INSTALL "Generate install targets for Vanetza" ON)
include(GNUInstallDirs)
include(UseVanetza)
-- Enable usage of targets' folder property (good for Visual Studio)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
-- Find project dependencies
set(Boost_COMPONENTS date_time) # used by VanetzaConfig generator
find_package(Boost 1.58 REQUIRED COMPONENTS ${Boost_COMPONENTS})
-- query optional Boost components one by one quietly
foreach(component IN ITEMS program_options system)
find_package(Boost 1.58 QUIET COMPONENTS ${component})
if (Boost_${component}_FOUND)
list(APPEND Boost_COMPONENTS ${component})
endif()
endforeach()
include(CompatBoostTargets)
find_package(CryptoPP 5.6.1 REQUIRED)
find_package(GeographicLib 1.37 REQUIRED)
find_package(Cohda MODULE QUIET)
option(VANETZA_WITH_OPENSSL "Enable OpenSSL extensions" OFF)
if (VANETZA_WITH_OPENSSL)
find_package(OpenSSL 1.0.1 REQUIRED)
include(CompatOpenSSLTargets)
endif()
add_subdirectory(vanetza/access)
add_subdirectory(vanetza/asn1)
add_subdirectory(vanetza/btp)
add_subdirectory(vanetza/common)
add_subdirectory(vanetza/dcc)
add_subdirectory(vanetza/facilities)
add_subdirectory(vanetza/geonet)
add_subdirectory(vanetza/gnss)
add_subdirectory(vanetza/net)
add_subdirectory(vanetza/security)
add_subdirectory(vanetza/units)
add_subdirectory(tools/proxy_fake_feed)
if(TARGET Cohda::headers)
add_subdirectory(tools/cohda_proxy)
endif()
option(BUILD_SOCKTAP "Build socktap application" OFF)
if(BUILD_SOCKTAP)
add_subdirectory(tools/socktap)
endif()
option(BUILD_CERTIFY "Build certify application" OFF)
if(BUILD_CERTIFY)
add_subdirectory(tools/certify)
endif()
option(BUILD_BENCHMARK "Build benchmark application" OFF)
if(BUILD_BENCHMARK)
add_subdirectory(tools/benchmark)
endif()
-- interface library for convenience
get_property(_components GLOBAL PROPERTY VANETZA_COMPONENTS)
add_library(vanetza INTERFACE)
add_library(Vanetza::vanetza ALIAS vanetza)
foreach(_component IN LISTS _components)
target_link_libraries(vanetza INTERFACE ${_component})
endforeach()
-- installation rules
include(CMakePackageConfigHelpers)
set(CMAKECONFIG_INSTALL_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/Vanetza")
set(CMAKECONFIG_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/cmake-config")
write_basic_package_version_file(${CMAKECONFIG_BUILD_DIR}/VanetzaConfigVersion.cmake
COMPATIBILITY ExactVersion)
configure_package_config_file(cmake/VanetzaConfig.cmake.in
${CMAKECONFIG_BUILD_DIR}/VanetzaConfig.cmake
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
PATH_VARS CMAKE_INSTALL_INCLUDEDIR)
if(VANETZA_INSTALL)
install(TARGETS vanetza EXPORT ${PROJECT_NAME})
install(FILES
${CMAKECONFIG_BUILD_DIR}/VanetzaConfig.cmake
${CMAKECONFIG_BUILD_DIR}/VanetzaConfigVersion.cmake
DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(DIRECTORY ${PROJECT_SOURCE_DIR}/vanetza-master/cmake/
DESTINATION ${CMAKECONFIG_INSTALL_DIR}
FILES_MATCHING
PATTERN "MacroFindDependencyComponents.cmake"
PATTERN "Find*.cmake"
PATTERN "Compat*Targets.cmake")
install(EXPORT ${PROJECT_NAME} NAMESPACE Vanetza:: FILE VanetzaTargets.cmake DESTINATION ${CMAKECONFIG_INSTALL_DIR})
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vanetza
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN ".hpp" PATTERN "/tests/.hpp" EXCLUDE)
-- export build tree (allows import by outside projects)
option(VANETZA_EXPORT_PACKAGE "Export Vanetza build directory to CMake package registry" ON)
if(VANETZA_EXPORT_PACKAGE)
export(EXPORT ${PROJECT_NAME} NAMESPACE Vanetza:: FILE VanetzaExports.cmake)
file(COPY ${CMAKECONFIG_BUILD_DIR}/VanetzaConfigVersion.cmake
DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
configure_file(cmake/VanetzaExportsConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/VanetzaConfig.cmake @only)
export(PACKAGE ${PROJECT_NAME})
endif()
endif(VANETZA_INSTALL)
`
Dear @ekamberoglu,
it is perfectly possible to add Vanetza as a sub-project to another CMake project. Be aware that some sources/headers of Vanetza depend on further libraries (e.g. gps_position_provider.cpp depends on libgps) or a particular platform.
In essence, your project's CMakeLists.txt just needs the following line:
add_subdirectory(${PROJECT_SOURCE_DIR}/vanetza-master)
target_link_libraries(c-v2x PUBLIC Vanetza::vanetza)
See also the Artery project for reference, which incorporates Vanetza as well: https://github.com/riebl/artery/blob/master/CMakeLists.txt