我在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文件夹,但它无法正常工作。 我做错了什么?
答案 0 :(得分:1)
尝试设置这些变量:
CMAKE_BINARY_DIR
CMAKE_CURRENT_BINARY_DIR
您可以在此处尝试完整的变量列表:
答案 1 :(得分:1)
命令
install(.. DESTINATION <dir>)
安装到${CMAKE_INSTALL_PREFIX}/<dir>
。
您需要在CMakeLists.txt或调用CMAKE_INSTALL_PREFIX
时设置cmake
:
cmake ... -DCMAKE_INSTALL_PREFIX=<dir>