当我使用cmake -G "Xcode"
使用CMake设置XCode项目,并在Xcode中打开它时,运行的选项显示为灰色,我只能构建项目。环顾四周透露,这可能是因为XCode将其视为库而非可执行文件。如何使用cmake以便在构建文件后运行该文件?
编辑:这是我的CMakeLists.txt
# Get the exercise name from the current directory
get_filename_component(exercise ${CMAKE_CURRENT_SOURCE_DIR} NAME)
# Basic CMake project
cmake_minimum_required(VERSION 2.8.11)
# Name the project after the exercise
project(${exercise} CXX)
# Locate Boost libraries: unit_test_framework, date_time and regex
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost 1.55 REQUIRED COMPONENTS unit_test_framework date_time regex)
# gcc/clang won't enable C++11 features without this flag
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "(GNU|Clang)")
set(CMAKE_CXX_FLAGS "-std=c++11")
endif()
# Configure to run all the tests?
if(${EXERCISM_RUN_ALL_TESTS})
add_definitions(-DEXERCISM_RUN_ALL_TESTS)
endif()
# Make an executable that runs the exercism unit tests against the implementation
function(exercism)
# Replace -'s with _'s to get a filename from the exercise name
string(REPLACE "-" "_" file ${exercise})
# Implementation could be only a header
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file}.cpp)
set(exercise_cpp ${file}.cpp)
else()
set(exercise_cpp "")
endif()
# Build executable from sources and headers
add_executable(${exercise} ${file}_test.cpp ${exercise_cpp} ${file}.h)
# We need boost includes
target_include_directories(${exercise} PRIVATE ${Boost_INCLUDE_DIRS})
# We need boost libraries
target_link_libraries(${exercise} ${Boost_LIBRARIES})
# Run the tests on every build
add_custom_command(TARGET ${exercise} POST_BUILD COMMAND ${exercise})
endfunction()
exercism()
这包含在一组练习中,要求您使用Boost编写通过测试的文件。我不熟悉cmake,但我需要它创建的Xcode项目可以运行。
答案 0 :(得分:0)
我一直在做一个类似的项目,我发现XCode中的“Products”都是红色的,“Run”命令是灰色的。
如果查看测试可执行产品的“标识和类型”窗格,您可能会发现列出的路径不是实际的输出路径。
我已经完成了这个匹配,并且通过修改构建设置来启用运行命令。顶级项目的“构建产品路径”似乎确定了“产品”列表中预期的路径。每个目标的“构建产品路径”似乎决定了产品输出的实际位置。因此,通过手动更改这些直到预期和实际输出匹配,您可以启用“运行”命令。
可能会对CMake文件进行一次自动调整,但我还没弄清楚它是什么。