无法使用cmake找到头文件

时间:2019-06-21 17:03:09

标签: c++ ios cmake

我的项目结构:

.
├── CMakeLists.txt
├── src  //mainly source codes
│   ├──view
│      ├── BaseView.cpp
├── platform
├────── ios //this is some objective-c codes
├      ├── VPBaseController.h
├      ├── VPBaseController.mm

我的CMakeLists.txt:

set(SYSTEM_IOS TRUE)
include_directories(
                ${PROJECT_SOURCE_DIR}/3rdparty/libevent/ios/include
                ${PROJECT_SOURCE_DIR}/platform/ios //just try, no works
)
include_directories(${PROJECT_SOURCE_DIR}/src)
SET(CMAKE_CXX_STANDARD 11)

file(GLOB_RECURSE SHOULD_BE_OC_FILES platform/ios/*.mm platform/ios/*.m platform/ios/*.h Logger.cpp BaseView.cpp)
set_source_files_properties(${SHOULD_BE_OC_FILES} PROPERTIES 
                            COMPILE_FLAGS "-x objective-c++")

file(GLOB_RECURSE EXTRA_FILES platform/ios/*.mm platform/ios/*.m platform/ios/*.h)    

file(GLOB_RECURSE SOURCE_FILES
        "src/*.cpp"
        "src/*.c"
        "src/*.h"
        "src/*.hpp")
source_group(${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCE_FILES})
add_library(
    mylib static
    ${SOURCE_FILES} ${EXTRA_FILES})
target_link_libraries(${LIB_NAME} ${LIBEVENT} ${LIBPCDN} ${EXTRA_LIBS})

set_property (TARGET mylib APPEND_STRING PROPERTY COMPILE_FLAGS "-fobjc-arc")            
    set(CMAKE_XCODE_ATTRIBUTE_DEBUG_INFORMATION_FORMAT "dwarf-with-dsym")
    file(GLOB_RECURSE IOS_PUBLIC_HEADERS "${PROJECT_SOURCE_DIR}/platform/ios/*.h")

    set(FRAMEWORK_BUNDLE_IDENTIFIER "my.goodlib")       # framework's bundle identifier
    set(DEPLOYMENT_TARGET 8.0)                                  # deployment target version of iOS
    set(DEVELOPMENT_TEAM_ID "Tyrion chen(personal)")                      # team ID
    set(DEVICE_FAMILY "1")                                      # Set to "1" to target iPhone, set to "2" to target iPad
    set(CODE_SIGN_IDENTITY "iPhone Developer")                  # code sign identity, to see list:
                                                                # /usr/bin/env xcrun security find-identity -v -p codesigning

    set_target_properties(${LIB_NAME} 
    PROPERTIES
    FRAMEWORK TRUE
    FRAMEWORK_VERSION A
    MACOSX_FRAMEWORK_IDENTIFIER ${FRAMEWORK_BUNDLE_IDENTIFIER}
    MACOSX_FRAMEWORK_INFO_PLIST "${PROJECT_SOURCE_DIR}/platform/ios/Info.plist"
    # "current version" in semantic format in Mach-O binary file
    VERSION 1.0.0
    # "compatibility version" in semantic format in Mach-O binary file
    SOVERSION 1.0.0
    PUBLIC_HEADER "${IOS_PUBLIC_HEADERS}"
    XCODE_ATTRIBUTE_IPHONEOS_DEPLOYMENT_TARGET ${DEPLOYMENT_TARGET}
    XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY ${CODE_SIGN_IDENTITY}
    XCODE_ATTRIBUTE_DEVELOPMENT_TEAM ${DEVELOPMENT_TEAM_ID}
    XCODE_ATTRIBUTE_TARGETED_DEVICE_FAMILY ${DEVICE_FAMILY}
    XCODE_ATTRIBUTE_SKIP_INSTALL "YES"
    )

    set_target_properties(${FRAMEWORK_NAME} PROPERTIES
    COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden"
    XCODE_ATTRIBUTE_OTHER_CFLAGS "-fvisibility=hidden -fvisibility-inlines-hidden")

我进入目录AdvanceP2P-ng,类型为:

cmake . -B ./platform/ios/build -DCMAKE_TOOLCHAIN_FILE=./ios.toolchain.cmake

一切都很好,某些文件是在AdvanceP2P-ng / platform / ios / build中自动创建的。然后我转到AdvanceP2P-ng / platform / ios / build,键入 :

make

它开始构建,当过程达到87%时,发生错误 找不到“ platform / ios / VPBaseController.h”文件

[ 87%] Building CXX object CMakeFiles/TP.dir/src/view/BaseView.cpp.o
/Users/yanyin/Desktop/projects/AdvanceP2P-ng/src/view/BaseView.cpp:9:9: fatal error: 'platform/ios/VPBaseController.h' file not found
#import "platform/ios/VPBaseController.h"
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/TP.dir/src/view/BaseView.cpp.o] Error 1
make[1]: *** [CMakeFiles/TP.dir/all] Error 2
make: *** [all] Error 2

我想可能没有头文件的目录,我输入:

make -n

进行检查:

/usr/bin/clang++ -DTP_EXPORTS -I/Users/yanyin/Desktop/projects/AdvanceP2P-ng/platform/ios -I/Users/yanyin/Desktop/projects/AdvanceP2P-ng/3rdparty/libevent/ios/include -I/Users/yanyin/Desktop/projects/AdvanceP2P-ng/src  -std=c++11 -Wall -fmessage-length=0 -fPIC -O3 -DNDEBUG -Os -ffunction-sections -fdata-sections -fvisibility=hidden -arch armv7 -arch armv7s -arch arm64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.2.sdk -fPIC   -fobjc-arc -DIOS -std=gnu++11 -x objective-c++ -o CMakeFiles/TP.dir/src/view/BaseView.cpp.o -c /Users/yanyin/Desktop/projects/AdvanceP2P-ng/src/view/BaseView.cpp

当编译文件BaseView.cpp时,VPBaseController.h文件的目录已在其中: -I / Users / yanyin / Desktop / projects / AdvanceP2P-ng / platform / ios

有人帮忙吗?还是谢谢。

0 个答案:

没有答案