1

我在 CMake 中有一个目录结构,如下所示:

root
    CMakeLists.txt
    subproject_folder
        my_dll_library
        CMakeLists.txt
            src
                source1.cpp
                source2.cpp
            inc
                library.h
            CMakeLists.txt
        library_demo
            src
                demo.cpp
            CMakeLists.txt
    build
    bin

我的根 CmakeLists.txt 包含以下内容:

cmake_minimum_required(VERSION 2.8)
add_subdirectory(subproject_folder)
if(MSVC)
# Force to always compile with W4
    if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
            string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    else()
            set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
    elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
    # Update if necessary
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
    endif()
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin)

子项目文件夹中的 CMakeLists 只包含

add_subdirectory(my_dll_library)
add_subdirectory(library_demo)

library_demo 文件夹中的 CMakeLists 包含

project(library_demo)
add_executable(librarydemo src/demo.cpp)
target_link_libraries(librarydemo my_dll_library)
install(TARGETS librarydemo DESTINATION bin)

my_dll_library 文件夹中的 CMakeLists 包含

add_library(lib_zaber SHARED src/source1.cpp src/source2.cpp)
install(TARGETS lib_zaber DESTINATION bin)

我想将演示可执行文件和库 DLL 复制到 bin 文件夹,但它不起作用。我究竟做错了什么?

4

2 回答 2

2

Try to set those variables too:

CMAKE_BINARY_DIR
CMAKE_CURRENT_BINARY_DIR

There's a whole list of variables you could try here:

http://www.cmake.org/Wiki/CMake_Useful_Variables

于 2013-09-19T06:26:13.943 回答
1

命令

install(.. DESTINATION <dir>)

安装到${CMAKE_INSTALL_PREFIX}/<dir>.

您需要CMAKE_INSTALL_PREFIX在 CMakeLists.txt 或调用时设置cmake

cmake ... -DCMAKE_INSTALL_PREFIX=<dir>
于 2014-04-30T20:50:37.420 回答