简体   繁体   English

使用CMake创建iOS静态库时出错

[英]Error creating iOS Static Library using CMake

I'm trying to create a static library of the project json11 with CMake, to use in a iOS project. 我正在尝试使用CMake创建项目json11的静态库,以便在iOS项目中使用。

I had created a sample project here: https://github.com/4brunu/json11CMakeiOS 我在这里创建了一个示例项目: https//github.com/4brunu/json11CMakeiOS

When building the json11 target it work's fine, but the json11_test target return's the following error: 构建json11目标时它工作正常,但json11_test目标返回以下错误:

=== BUILD TARGET json11_test OF PROJECT example_all WITH CONFIGURATION Debug ===

Check dependencies
target specifies product type 'com.apple.product-type.tool', but there's no such product type for the 'iphoneos' platform

** BUILD FAILED **


The following build commands failed:
    Check dependencies
(1 failure)

The original json11 CMakeLists.txt is this: 原来的json11 CMakeLists.txt是这样的:

cmake_minimum_required(VERSION 3.2)
project(json11 VERSION 1.0.0 LANGUAGES CXX)

enable_testing()

add_library(json11 json11.cpp)
target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(json11
  PUBLIC -std=c++11
  PRIVATE -fno-rtti -fno-exceptions -Wall -Wextra -Werror)
configure_file("json11.pc.in" "json11.pc" @ONLY)

add_executable(json11_test test.cpp)
target_link_libraries(json11_test json11)

install(TARGETS json11 DESTINATION lib)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include)
install(FILES "${CMAKE_BINARY_DIR}/json11.pc" DESTINATION lib/pkgconfig)

After some test's, I had modified the CMakeLists.txt and it works, but I'm trying to figure out what's wrong. 经过一些测试后,我修改了CMakeLists.txt并且它可以工作,但我正在试图弄清楚什么是错的。

cmake_minimum_required(VERSION 3.2)
project(json11 VERSION 1.0.0 LANGUAGES CXX)

enable_testing()

add_library(json11 json11.cpp)
target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(json11
  PUBLIC -std=c++11
  PRIVATE -fno-rtti -fno-exceptions -Wall -Wextra -Werror)
configure_file("json11.pc.in" "json11.pc" @ONLY)

# Commented this two lines
# add_executable(json11_test test.cpp)
# target_link_libraries(json11_test json11)

install(TARGETS json11 DESTINATION lib)
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/json11.hpp" DESTINATION include)
install(FILES "${CMAKE_BINARY_DIR}/json11.pc" DESTINATION lib/pkgconfig)

Not sure if the issue is in the CMake configuration 1 2 , the iOS toolchain , json11 CMake , or any other thing. 不确定问题是在CMake配置1 2iOS工具链json11 CMake还是其他任何东西。

Thanks for the help. 谢谢您的帮助。

EDIT 编辑

I have not found a solution but rather a work around, making the tests optional. 我没有找到解决方案,而是一个解决方案,使测试可选。

https://github.com/4brunu/json11CMakeiOS/commit/972f00b646057a513d14a90b874f9f398fcff873 https://github.com/dropbox/json11/pull/66 https://github.com/4brunu/json11CMakeiOS/commit/972f00b646057a513d14a90b874f9f398fcff873 https://github.com/dropbox/json11/pull/66

The problem is the test target that comes with the library. 问题是库附带的测试目标。 In C and C++ you usual have a dedicated command line executable that runs a test suite. 在C和C ++中,您通常会有一个运行测试套件的专用命令行可执行文件。 On OSX there is target type for that called Command Line Tool . 在OSX上,有一个名为命令行工具的目标类型。 Xcode references target types with a reverse DNS identifier, in this case com.apple.product-type.tool . Xcode引用具有反向DNS标识符的目标类型,在本例中为com.apple.product-type.tool On iOS you do not have a target type for command line tools because, well, there is no public command line that you could run the executable from. 在iOS上,您没有命令行工具的目标类型,因为没有可以从中运行可执行文件的公共命令行。

That being said, you have already found the solution yourself: deactivate the test target generation in CMake for that library if you want to build for iOS. 话虽如此,您已经自己找到了解决方案:如果您想为iOS构建,请在CMake中停用测试目标生成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM