1、使用boostwindows
一、一個簡單的windows下使用boost的程序,其中CMakeFiles.txt測試
cmake_minimum_required(VERSION 2.6)
project(cpp11)
set(CPP11_VERSION_MAJOR 1)
set(CPP11_VERSION_MINOR 0)
configure_file(
"${PROJECT_SOURCE_DIR}/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
add_definitions(-DBOOST_ALL_DYN_LINK)
include_directories("${PROJECT_BINARY_DIR}")
add_executable(demo_server1 demo_server1.cpp)
set(BOOST_ROOT "d:\\sdk\\boost")
include_directories(${Boost_INCLUDE_DIR})
find_package(Boost 1.57.0 COMPONENTS system date_time regex REQUIRED)
target_link_libraries(demo_server1 ${Boost_SYSTEM_LIBRARY}
${Boost_DATE_TIME_LIBRARY}
${Boost_REGEX_LIBRARY}
)ui
二、config.h.inserver
#define CPP11_VERSION_MAJOR @CPP11_VERSION_MAJOR@get
#define CPP11_VERSION_MINOR @CPP11_VERSION_MINOR@it
三、創建build子目錄,在子目錄下執行cmake ..後,進行相關的編譯工做。io
2、區分32位與64位asm
一、CMakeLists.txt,使用CMAKE_SIZEOF_VOID_P判斷編譯
cmake_minimum_required (VERSION 2.6)
project (uthread)
SET(CMAKE_BUILD_TYPE release)
SET (CMAKE_C_FLAGS_RELEASE "-g -Wall")table
set(LWTHREAD_VERSION_MAJOR 1)
set(LWTHREAD_VERSION_MINOR 0)
include_directories("include")
set(uthread_srcs src/uthread.cpp)
set(context01_files tests/context01.cpp)
if (CMAKE_SYSTEM_NAME MATCHES "Windows")
enable_language(ASM_MASM)
include_directories(src/win)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(uthread_srcs ${uthread_srcs} src/win/ucontext_x64.asm)
set(context01_files ${context01_files} src/win/ucontext.cpp src/win/ucontext_x64.asm)
else (CMAKE_SIZEOF_VOID_P EQUAL 8)
set(uthread_srcs ${uthread_srcs} src/win/ucontext_x86.asm)
set(context01_files ${context01_files} src/win/ucontext.cpp src/win/ucontext_x86.asm)
endif (CMAKE_SIZEOF_VOID_P EQUAL 8)
endif (CMAKE_SYSTEM_NAME MATCHES "Windows")
add_library(uthread STATIC ${uthread_srcs})
add_executable(context01 ${context01_files})
二、使用cmake -G "Visual Studio 10 2010 Win64"生成64位編譯配置。
3、使用匯編
一、使用enable_language(ASM_MASM)啓用匯編,其它的有ASM-ATT等。
4、Windows下DLL加上符號導出宏
一、DEFINE_SYMBOL屬性設置了編譯一個共享庫中的源文件時纔會被定義的預處理器符號名。若是這個值沒有被設置的話,那麼它會被設置爲默認值target_EXPORTS。
......
#動態庫編譯時會加上THREADKIT_EXPORTS
add_library(ThreadKit SHARED ${srcs})
set_target_properties(ThreadKit PROPERTIES DEFINE_SYMBOL THREADKIT_EXPORTS)
#測試程序不會加上-DTHREADKIT_EXPORTS
set(idtest_files test/ThreadIDTest.cpp)
add_executable(ThreadIDTest ${idtest_files})
target_link_libraries(ThreadIDTest ThreadKit)
5、子目錄做爲另外一個項目
add_directory(test)
test目錄下也須要有CMakeLists.txt。
6、將一下目錄下的文件名設置到一個變量
aux_source_directory(src SRCS)
得到目錄src下全部源文件,至關於set(SRCS src/xxx1 src/xxx2 ....)
7、CMAKE參數
cmake -DCMAKE_BUILD_TYPE=release ..
8、make時詳細輸出
make VERBOSE=1
或在CMakeLists.txt中加入set(CMAKE_VERBOSE_MAKEFILE ON)。