2016-09-05 68 views
2

我尝试构建CommonApi Some/IP项目。本教程是从本网站:CommonAPI Some/IP TutorialCommonAPI CMake错误

我现在试图建立CPP-someip运行时与cmake的GUI。如果我尝试生成项目我得到这个错误:

The C compiler identification is MSVC 18.0.21005.1 
The CXX compiler identification is MSVC 18.0.21005.1 
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe 
Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe -- works 
Detecting C compiler ABI info 
Detecting C compiler ABI info - done 
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe 
Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio 12.0/VC/bin/x86_amd64/cl.exe -- works 
Detecting CXX compiler ABI info 
Detecting CXX compiler ABI info - done 
Detecting CXX compile features 
Detecting CXX compile features - done 
Project name: CommonAPI-SomeIP 
Looking for pthread.h 
Looking for pthread.h - not found 
Found Threads: TRUE 
Boost version: 1.55.0 
Found the following Boost libraries: 
    system 
    thread 
    log 
    chrono 
    date_time 
    atomic 
    log_setup 
    filesystem 
    regex 
MAX_LOG_LEVEL is set to value: DEBUG 
CMake Error at CMakeLists.txt:92 (set): 
    set called with incorrect number of arguments 


CMake Error at CMakeLists.txt:96 (FIND_PACKAGE): 
    Could not find a package configuration file provided by "CommonAPI" 
    (requested version 3.1.5) with any of the following names: 

    CommonAPIConfig.cmake 
    commonapi-config.cmake 

    Add the installation prefix of "CommonAPI" to CMAKE_PREFIX_PATH or set 
    "CommonAPI_DIR" to a directory containing one of the above files. If 
    "CommonAPI" provides a separate development package or SDK, be sure it has 
    been installed. 


Configuring incomplete, errors occurred! 
See also "D:/Programmieren/cplusplus/commonapi/cpp-someip-runtime/build/CMakeFiles/CMakeOutput.log". 
See also "D:/Programmieren/cplusplus/commonapi/cpp-someip-runtime/build/CMakeFiles/CMakeError.log". 

这是的CMakeLists.txt:

# Copyright (C) 2013-2015 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) 
# This Source Code Form is subject to the terms of the Mozilla Public 
# License, v. 2.0. If a copy of the MPL was not distributed with this 
# file, You can obtain one at http://mozilla.org/MPL/2.0/. 

cmake_minimum_required (VERSION 2.8) 

project (CommonAPI-SomeIP) 

set (CMAKE_VERBOSE_MAKEFILE off) 

set (LIBCOMMONAPI_SOMEIP_MAJOR_VERSION 3) 
set (LIBCOMMONAPI_SOMEIP_MINOR_VERSION 1) 
set (LIBCOMMONAPI_SOMEIP_PATCH_VERSION 5) 
set (USE_INSTALLED_COMMONAPI OFF) 

message(STATUS "Project name: ${PROJECT_NAME}") 

set (COMPONENT_VERSION ${LIBCOMMONAPI_SOMEIP_MAJOR_VERSION}.${LIBCOMMONAPI_SOMEIP_MINOR_VERSION}.${LIBCOMMONAPI_SOMEIP_PATCH_VERSION}) 
set (COMMONAPI_API_HEADER_VERSION ${LIBCOMMONAPI_SOMEIP_MAJOR_VERSION}.${LIBCOMMONAPI_SOMEIP_MINOR_VERSION}) 

SET(PACKAGE_VERSION "${COMPONENT_VERSION}") # used in *.cmake.in 

if (MSVC) 
# Boost 
set(Boost_USE_STATIC_LIBS ON) 
set(BOOST_ROOT "C:/portableapps/boost_1_55_0") 
find_package(Boost 1.54 COMPONENTS system thread log REQUIRED) 
include_directories(${Boost_INCLUDE_DIR}) 
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_CRT_SECURE_NO_WARNINGS") 
link_directories(${Boost_LIBRARY_DIR}) 
else() 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -Wall -Wextra -Wformat -Wformat-security -Wconversion -fexceptions -fstrict-aliasing -fstack-protector -fasynchronous-unwind-tables -fno-omit-frame-pointer -DCOMMONAPI_INTERNAL_COMPILATION -D_GLIBCXX_USE_NANOSLEEP") 
endif() 

SET(MAX_LOG_LEVEL "DEBUG" CACHE STRING "maximum log level") 
message(STATUS "MAX_LOG_LEVEL is set to value: ${MAX_LOG_LEVEL}") 

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_INTERNAL_COMPILATION") 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_SOMEIP_VERSION_MAJOR=${LIBCOMMONAPI_SOMEIP_MAJOR_VERSION}") 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_SOMEIP_VERSION_MINOR=${LIBCOMMONAPI_SOMEIP_MINOR_VERSION}") 
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DCOMMONAPI_LOGLEVEL=COMMONAPI_LOGLEVEL_${MAX_LOG_LEVEL}") 

# Package config module not found message macro 
macro (pkg_config_module_not_found_message PKG_CONFIG_MODULE) 
    message (FATAL_ERROR "pkg-config could not find the required module ${PKG_CONFIG_MODULE}!" 
     " Please adjust your PKG_CONFIG_PATH environment variable accordingly.") 
endmacro() 

# BEGIN TEMPORARY WORKAROUND # 
# OS 
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 
    set (OS "LINUX") 
    set (NO_DEPRECATED_REGISTER "") 
endif (${CMAKE_SYSTEM_NAME} MATCHES "Linux") 

if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 
    set (OS "FREEBSD") 
    set (NO_DEPRECATED_REGISTER "-Wno-deprecated-register") 
endif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") 

if (NOT MSVC) 
    set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D${OS} ${NO_DEPRECATED_REGISTER} -DBOOST_LOG_DYN_LINK -pthread -g -std=c++0x -O0") 
endif() 
# END TEMPORARY WORKAROUND # 

################################################################################################### 
# see http://www.cmake.org/Wiki/CMake/Tutorials/How_to_create_a_ProjectConfig.cmake_file 
################################################################################################### 

# Offer the user the choice of overriding the installation directories 
set (INSTALL_LIB_DIR lib CACHE PATH "Installation directory for libraries") 
set (INSTALL_INCLUDE_DIR include/CommonAPI-${COMMONAPI_API_HEADER_VERSION} CACHE PATH "Installation directory for header files") 

if (WIN32 AND NOT CYGWIN) 
    set (DEF_INSTALL_CMAKE_DIR cmake) 
else() 
    set (DEF_INSTALL_CMAKE_DIR lib/cmake/CommonAPI-SomeIP-${COMPONENT_VERSION}) 
endif() 

set (INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") 

# Make relative paths absolute (needed later on) 
foreach (p LIB BIN INCLUDE CMAKE) 
    set (var INSTALL_${p}_DIR) 
    if (NOT IS_ABSOLUTE "${${var}}") 
     set (ABSOLUTE_${var} "${CMAKE_INSTALL_PREFIX}/${${var}}") 
    endif() 
endforeach() 

################################################################################################### 
set() 
if ("${USE_INSTALLED_COMMONAPI}" STREQUAL "ON") 
    FIND_PACKAGE(CommonAPI 3.1.5 REQUIRED CONFIG NO_CMAKE_PACKAGE_REGISTRY) 
else() 
    FIND_PACKAGE(CommonAPI 3.1.5 REQUIRED CONFIG NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH) 
endif() 

message(STATUS "CommonAPI_CONSIDERED_CONFIGS: ${CommonAPI_CONSIDERED_CONFIGS}") 
message(STATUS "COMMONAPI_INCLUDE_DIRS: ${COMMONAPI_INCLUDE_DIRS}") 
message(STATUS "CommonAPI Version: ${CommonAPI_VERSION}") 

# Boost 
find_package(Boost 1.54 COMPONENTS system thread log REQUIRED) 
include_directories(${Boost_INCLUDE_DIR}) 

find_package (vsomeip 2.0.1 REQUIRED) 
message(STATUS "vsomeip version: ${vsomeip_VERSION}") 

include_directories (
    ${Boost_INCLUDE_DIR} 
    ${COMMONAPI_INCLUDE_DIRS} 
    ${VSOMEIP_INCLUDE_DIRS} 
    include 
) 

file (GLOB CommonAPI-SomeIP_SRC "src/CommonAPI/SomeIP/*.cpp") 

if (MSVC) 
set (RPCRT Rpcrt4) 
else() 
set (RPCRT "") 
endif() 

# CommonAPI 
add_library (CommonAPI-SomeIP SHARED ${CommonAPI-SomeIP_SRC}) 
set_target_properties (CommonAPI-SomeIP PROPERTIES VERSION ${COMPONENT_VERSION} SOVERSION ${LIBCOMMONAPI_SOMEIP_MAJOR_VERSION}) 
target_link_libraries (CommonAPI-SomeIP CommonAPI vsomeip ${RPCRT}) 

################################################################################################### 

file (GLOB_RECURSE CommonAPI-SomeIP_INCLUDE_INSTALL_FILES "include/*.hpp") 

set_target_properties (CommonAPI-SomeIP PROPERTIES PUBLIC_HEADER "${CommonAPI-SomeIP_INCLUDE_INSTALL_FILES}") 

install (
    TARGETS CommonAPI-SomeIP 
    # IMPORTANT: Add the CommonAPI-SomeIP library to the "export-set" 
    EXPORT CommonAPI-SomeIPTargets 
    LIBRARY DESTINATION "${INSTALL_LIB_DIR}" 
    RUNTIME DESTINATION "${PROJECT_BINARY_DIR}/Bin" 
    PUBLIC_HEADER DESTINATION "${INSTALL_INCLUDE_DIR}/CommonAPI/SomeIP" 
) 

############################################################################## 
# exporting, configuring and installing of cmake files 

# Add all targets to the build-tree export set 
export (TARGETS CommonAPI-SomeIP 
     FILE "${PROJECT_BINARY_DIR}/CommonAPI-SomeIPTargets.cmake") 

# Export the package for use from the build-tree 
# (this registers the build-tree with a global CMake-registry) 
export (PACKAGE CommonAPI-SomeIP) 

# Create the CommonAPI-SomeIPConfig.cmake and CommonAPI-SomeIPConfigVersion files 
file (RELATIVE_PATH REL_INCLUDE_DIR "${ABSOLUTE_INSTALL_CMAKE_DIR}" "${ABSOLUTE_INSTALL_INCLUDE_DIR}") 

# ... for the build tree 
set (CONF_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/include") 
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfig.cmake.in 
    "${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfig.cmake" @ONLY) 

# ... for the install tree 
set (CONF_INCLUDE_DIRS "\${COMMONAPI_SOMEIP_CMAKE_DIR}/${REL_INCLUDE_DIR}") 
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfig.cmake.in 
    "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CommonAPI-SomeIPConfig.cmake" @ONLY) 

# ... for both 
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/CommonAPI-SomeIPConfigVersion.cmake.in 
    "${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfigVersion.cmake" @ONLY) 

# Install the CommonAPI-SomeIPConfig.cmake and CommonAPI-SomeIPConfigVersion.cmake 
install (
    FILES 
    "${PROJECT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CommonAPI-SomeIPConfig.cmake" 
    "${PROJECT_BINARY_DIR}/CommonAPI-SomeIPConfigVersion.cmake" 
    DESTINATION "${INSTALL_CMAKE_DIR}" 
) 

# Install the export set for use with the install-tree 
install (
    EXPORT CommonAPI-SomeIPTargets 
    DESTINATION "${INSTALL_CMAKE_DIR}" 
) 

############################################################################## 
# create pkg-config file 
if(NOT WIN32) 
     configure_file(CommonAPI-SomeIP.pc.in ${PROJECT_BINARY_DIR}/CommonAPI-SomeIP.pc @ONLY) 
     install(FILES ${PROJECT_BINARY_DIR}/CommonAPI-SomeIP.pc DESTINATION lib/pkgconfig) 
endif() 

############################################################################## 
# maintainer-clean 
add_custom_target(maintainer-clean COMMAND rm -rf *) 

我是一个初学者的CMake所以请尽量在低水平解释一下我做错了。感谢您的帮助!

回答

4

以下是错误:

CMake Error at CMakeLists.txt:96 (FIND_PACKAGE): 
    Could not find a package configuration file provided by "CommonAPI" 
    (requested version 3.1.5) with any of the following names: 

    CommonAPIConfig.cmake 
    commonapi-config.cmake 

    Add the installation prefix of "CommonAPI" to CMAKE_PREFIX_PATH or set 
    "CommonAPI_DIR" to a directory containing one of the above files. If 
    "CommonAPI" provides a separate development package or SDK, be sure it has 
    been installed. 

CMake的是告诉你它找不到所需的库CommonAPI。我真的不知道这个库,但似乎你正在试图建立“CommonAPI C++ SOME/IP”,但你需要建立“CommonAPI运行”第一。这是写在你链接的教程:

If you didn't pass the instructions of the page "CommonAPI C++ D-Bus in 10 minutes" then do it now for step 2 in order to get and build the CommonAPI runtime library.

所以从here首先做第2步。

如果您已经这样做了,并且CMake仍然无法找到它,请将CommonAPI_DIR变量设置为包含CommonAPIConfig.cmakecommonapi-config.cmake文件的目录。例如:

cmake -DCommonAPI_DIR=/some/path/somewhere .. 
+0

谢谢您的回答!我想我忘了做第二步。我会立即尝试,然后我们会看看它是否有效。 –

+0

现在它几乎奏效。我收到另一个错误,说“DBus_DIR”没有设置。我为DBus的方向设置了一个环境路径变量,但仍然出现错误。 –

+0

我也不得不手动设置** ** DBUS_Include_dir中的变量** **的CMakeLists.txt我** DBus_build_dir **和** ** DBus_build路径,然后我可以生成Visual Studio解决方案。 –