如何在命令行设置 CMake option() [英] How to set a CMake option() at command line
本文介绍了如何在命令行设置 CMake option()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个包含以下内容的 CMakeLists.txt
I created a CMakeLists.txt that contains the following
project(P4V)
cmake_minimum_required(VERSION 2.6)
option(BUILD_STATIC_LIBS "Build the static library" ON)
option(BUILD_SHARED_LIBS "Build the shared library" ON)
option(BUILD_TESTS "Build test programs" OFF)
include_directories(${CMAKE_SOURCE_DIR}/include)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
set(CMAKE_BUILD_TYPE Release)
add_subdirectory(src)
if(BUILD_TESTS)
add_subdirectory(tests)
endif(BUILD_TESTS)
默认情况下,BUILD_TESTS 处于关闭状态,如何在没有 CMake GUI 的情况下打开它,但使用 cmake 命令本身?我尝试了以下方法,但不起作用
By default BUILD_TESTS is OFF, how can I turn it ON without CMake GUI, but with cmake command itself? I tried the following, but it doesn't work
cmake .. -G %1 -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_TESTS=ON
推荐答案
删除 CMakeCache.txt 文件并试试这个:
Delete the CMakeCache.txt file and try this:
cmake -G %1 -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DBUILD_TESTS=ON ..
在包含路径之前,您必须输入所有命令行定义.
You have to enter all your command-line definitions before including the path.
这篇关于如何在命令行设置 CMake option()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文