我在 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 文件夹,但它不起作用。我究竟做错了什么?