CMake install project doesn't copy my executable to the folder I specify

前端 未结 1 1865
伪装坚强ぢ
伪装坚强ぢ 2021-02-15 04:20

I am just starting out with CMake. I\'ve successfully set up the most minimal Hello, World! C++ application possible for Visual Studio 2012 on Windows 7,

1条回答
  •  悲哀的现实
    2021-02-15 05:06

    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: Visual Studio 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 Visual Studio 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
    

    0 讨论(0)
提交回复
热议问题