cmake安装项目不会将我的可执行文件复制到我指定的文件夹 [英] cmake install project doesn't copy my executable to the folder I specify

查看:3020
本文介绍了cmake安装项目不会将我的可执行文件复制到我指定的文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚开始与Cmake。我已经成功设置了最小的hello world C ++应用程序可能的VS2012在Win7,但我有一个最后叨叨的东西,不是很对,我不明白为什么:(



我的文件夹结构是:

  [cmakeTest] 
- [build]
- [source]
- [helloWorld]
- main.cpp
- CMakeLists.txt
- CMakeLists.txt

我的main.cpp文件只是:

  #include< iostream> 

int main()
{
std :: cout<<Hello World!;
}

source / CMakeLists.txt is:

  cmake_minimum_required(VERSION 3.0.1)

#指定VS解决方案的项目名称
#VS项目将为每个指定的CMake目标创建

项目(cmakeTesting )

#设置安装目录
set(CMAKE_INSTALL_PREFIX $ {cmakeTesting_BINARY_DIR} / bin)

#生成管理器项目
#创建CMakePredefinedTargets文件夹与INSTALL和ZERO_CHECK

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

#从子目录中排队CMakeLists

add_subdirectory(helloWorld)



source / helloWorld / CMakeLists.txt is:

 #设置属性 - >通用 - >配置类型到应用程序(.exe)
#使用列出的源(main.cxx)创建helloWorld.exe
#添加源到解决方案资源管理器

add_executable(helloWorld main.cpp)

#创建一个名为executables的文件夹,并添加目标
#project(helloWorld.vcproj) it

set_property(TARGET helloWorld PROPERTY FOLDERexecutables)

#将逻辑添加到INSTALL.vcproj以将helloWorld.exe复制到dest dir

install(TARGETS helloWorld RUNTIME DESTINATION $ {PROJECT_BINARY_BIN} / bin)




  • 它在构建目录中创建VS解决方案/项目内容



  • 它会在/ build / helloWorld / Debug /和/ build / helloWorld / Release中创建exe文件)




无效:




  • VS说它已经将exe复制到/bin/helloWorld.exe但它没有>: - (



1> ------构建开始:项目:ZERO_CHECK,配置:发布Win32 ------



2> ------ Build started:项目:ALL_BUILD,配置:发布Win32 ------



2>构建所有项目



3> ------构建开始:项目:INSTALL,配置:发布Win32 ------



3> - 安装配置:释放



3> - 更新:/bin/helloWorld.exe



========== Build:3成功,0失败,1个最新,0个跳过========= =





我知道这似乎很讨厌,但我想确保我明白继续前进到更复杂的东西(PS我使用的是cmake客户端而不是命令行。)

解决方案

这可能只是一个错字。在source / helloWorld / CMakeLists.txt的最后一行我想你的意思是 PROJECT_BINARY_DIR ,而不是 PROJECT_BINARY_BIN



这里发生的是, $ {PROJECT_BINARY_BIN} / bin 解析为 / bin (在CMake中取消引用未定义的字符串不幸地不会生成警告), / bin 是一个绝对路径。如果你的项目是在C:驱动器,我希望你会发现C:\bin\helloWorld.exe实际上 存在:VS没有说谎: - ) / p>

同样,通常在 install 命令中指定相对路径以允许用户选择安装根。同样,硬编码 CMAKE_INSTALL_PREFIX (至少没有警告)也不是真正用户友好的。



这种情况下,我会将 install 命令更改为:

 安装(TARGETS helloWorld RUNTIME DESTINATION bin)

并删除 set(CMAKE_INSTALL_PREFIX ... )



说你的项目的根目录是C:\myProject,然后从VS命令提示符,你可以do:

  cd C:\myProject\build 
cmake -DCMAKE_INSTALL_PREFIX = C:\myProject\build..\source
cmake --build。 --config Release --target INSTALL
bin\helloWorld.exe


Just starting out with Cmake. I've successfully setup the most minimal hello world C++ app possible for VS2012 on Win7 but I've got one last nagging thing that's not quite right and I can't figure out why :(

My folder structure is:

[cmakeTest]
- [build]
- [source]
  - [helloWorld]
    - main.cpp
    - CMakeLists.txt
  - CMakeLists.txt

My main.cpp file is just:

#include <iostream>

int main()
{
    std::cout << "Hello World!";
}

source/CMakeLists.txt is:

cmake_minimum_required (VERSION 3.0.1)

# Specifies project name for VS solution
# VS projects will be made for each CMake target specified

project(cmakeTesting)

# set the install directory
set(CMAKE_INSTALL_PREFIX ${cmakeTesting_BINARY_DIR}/bin)

# Generate organiser projects
# Creates "CMakePredefinedTargets" folder with INSTALL and ZERO_CHECK

set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Queue up CMakeLists from subdirectories

add_subdirectory(helloWorld)

source/helloWorld/CMakeLists.txt is:

# Set Properties->General->Configuration Type to Application (.exe)
# Creates helloWorld.exe with the listed sources (main.cxx)
# Adds sources to the Solution Explorer

add_executable (helloWorld main.cpp)

# Creates a folder called "executables" and adds target
# project (helloWorld.vcproj) under it

set_property(TARGET helloWorld PROPERTY FOLDER "executables")

# Adds logic to INSTALL.vcproj to copy helloWorld.exe to dest dir

install (TARGETS helloWorld RUNTIME DESTINATION ${PROJECT_BINARY_BIN}/bin)

What does work:

  • It creates the VS solution/project stuff in the build directory

  • The project builds and runs in debug and release mode

  • It creates exe's in /build/helloWorld/Debug/ and /build/helloWorld/Release (which work)

What doesn't work:

  • VS says it has copied the exe to /bin/helloWorld.exe but it hasn't >:-(

.

1>------ Build started: Project: ZERO_CHECK, Configuration: Release Win32 ------

2>------ Build started: Project: ALL_BUILD, Configuration: Release Win32 ------

2> Build all projects

3>------ Build started: Project: INSTALL, Configuration: Release Win32 ------

3> -- Install configuration: "Release"

3> -- Up-to-date: /bin/helloWorld.exe

========== Build: 3 succeeded, 0 failed, 1 up-to-date, 0 skipped ==========

.

I know it seems fussy, but I'm trying to make sure I understand everything that's going on before steamrolling into more complex stuff (P.S. I'm using the cmake client not command line).

解决方案

This probably just boils down to being a typo. In the last line of source/helloWorld/CMakeLists.txt I guess you meant PROJECT_BINARY_DIR rather than PROJECT_BINARY_BIN?

What's happening here is that ${PROJECT_BINARY_BIN}/bin resolves to /bin (dereferencing an undefined string in CMake unfortunately doesn't generate a warning) and /bin is an absolute path. If your project is in the C: drive, I expect you'll find that C:\bin\helloWorld.exe actually does exist: VS hasn't been lying to you :-)

Just as an aside, it's usual to specify relative paths in the install command to allow the user to select the install root. Likewise, it's not really user-friendly to hard code the CMAKE_INSTALL_PREFIX (at least without a warning).

In this case, I'd change the install command to:

install (TARGETS helloWorld RUNTIME DESTINATION bin)

and remove set(CMAKE_INSTALL_PREFIX ...) from source/CMakeLists.txt.

Say your project's root is C:\myProject, then from a VS command prompt, you can do:

cd C:\myProject\build
cmake -DCMAKE_INSTALL_PREFIX="C:\myProject\build" ..\source
cmake --build . --config Release --target INSTALL
bin\helloWorld.exe

这篇关于cmake安装项目不会将我的可执行文件复制到我指定的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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