PROJECT(hello_2) cmake_minimum_required(VERSION 2.8) #cmake的最低版本 FILE(GLOB SOURCE_1 "${CMAKE_SOURCE_DIR}/main/*.cpp") #下面2句告訴CMake,源文件在哪裏?main.cpp FILE(GLOB SOURCE_2 "${CMAKE_SOURCE_DIR}/hello/*.cpp")#程序必須連接到hello.cpp裏面的SayHello INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}/include/")#告訴CMake頭文件在哪裏? ADD_EXECUTABLE(hello_2 ${SOURCE_1} ${SOURCE_2}) #生成可執行文件
PROJECT(hello) cmake_minimum_required(VERSION 2.8) SET(PROJECT_ROOT_PATH "${CMAKE_SOURCE_DIR}/../") #工程的根目錄,即test SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin/") #可執行文件生成後存放的目錄(CMAKE_SOURCE_DIR是cmake目錄) SET(LIBRARY_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/lib/") #靜態庫生成後存放的目錄 INCLUDE_DIRECTORIES("${PROJECT_ROOT_PATH}/include/") #告訴CMake頭文件在哪裏? LINK_DIRECTORIES("${CMAKE_SOURCE_DIR}/lib/")#告訴CMake靜態庫在哪裏? ADD_SUBDIRECTORY(src) #多目錄,把src目錄加進來,src裏面纔是真正編譯main和hello的
ADD_SUBDIRECTORY(main)
ADD_SUBDIRECTORY(hello)
FILE(GLOB SOURCE_1 "${PROJECT_ROOT_PATH}/hello/hello.cpp") #告訴CMake,源文件在哪裏? ADD_LIBRARY(hello STATIC ${SOURCE_1}) #打包成hello靜態庫 *.a---若是想生成動態庫*.so,將STATIC變爲SHARED
FILE(GLOB SOURCE_1 "${PROJECT_ROOT_PATH}/main/main.cpp") ADD_EXECUTABLE(main ${SOURCE_1}) #生成可執行文件 TARGET_LINK_LIBRARIES(main hello) #並在可執行文件上鍊接到這個庫