如何在命令行设置CMake option() [英] How to set a CMake option() at command line

查看:216
本文介绍了如何在命令行设置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为OFF,如何在不使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆