cmake学习
作者:互联网
demo文件夹下 1、build文件夹 2、src文件夹 3、SwapInt文件夹 4、CMakeLists.txt CMakeLists.txt 内容为: cmake_minimum_required(VERSION 3.0) project(demo) add_subdirectory(./SwapInt) add_subdirectory(./src)
src文件夹下有main.cpp和CMakeLists.txt main.cpp #include <iostream> #include "SwapInt.h" using namespace std; int main() { int a = 10; int b =20; SwapInt(a, b); cout<<"a = " << a <<", b = "<< b <<endl; } CMakeLists.txt include_directories(${PROJECT_SOURCE_DIR}/SwapInt) set(EXECUTABLES(${project_binary_dir}/bin)) aux_source_directory(./ DIR_SRCS) add_executable(demo4 ${DIR_SRCS}) target_link_libraries(demo4 SwapInt)
SwapInt文件夹下有 SwapInt.h SwapInt.cpp CMakeLists.txt SwapInt.h #ifndef SWAP_INT_H #define SWAP_INT_H void SwapInt(int& a, int& b); #endif SwapInt.cpp #include "SwapInt.h" void SwapInt(int&a, int& b) { int t; t = a; a = b; b = t; } CMakeLists.txt aux_source_directory(. DIR_LIB_SRCS) set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib) add_library(SwapInt SHARED ${DIR_LIB_SRCS})
到build文件夹下
cmake ..
make
标签:文件夹,CMakeLists,cmake,int,学习,SwapInt,cpp,txt 来源: https://www.cnblogs.com/crazybird123/p/16065380.html