cmake处理多源文件目录
假设我们的源文件全部在src中,则我们需要在子文件src中建立文件CmakeLists.txt,内容如下:
AUX_SOURCE_DIRECTORY(. DIR_TEST_SRCS)
ADD_LIBRARY (Test ${DIR_TEST_SRCS})
在主目录的CmakeLists.txt中添加两行内容:
ADD_SUBDIRECTORY( src )
target_link_libraries(main Test)
加上前面cmake模板,模板总结如下:
cmake_minimum_required (VERSION 2.6)
project (TEST)
set (TEST_VERSION 0.1)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g -ggdb -DDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../bin)
aux_source_directory(${PROJECT_SOURCE_DIR}/src DIR_SRC)
include_directories(${PROJECT_SOURCE_DIR}/src)
ADD_SUBDIRECTORY( src )
link_directories(${PROJECT_SOURCE_DIR}/lib)
add_executable(main ${DIR_SRC})
target_link_libraries(main Test)
target_link_libraries(main -lm)
target_link_libraries(main -lpthread)