通過增加編譯宏實現條件編譯
ADD_DEFINITIONS(-D宏名稱 -D宏名稱......)
camke文件如下:
-
cmake_minimum_required( VERSION 2.8)
-
PROJECT ( hello)
-
SET( SRC_LIST main.c)
-
MESSAGE( STATUS "This is BINARY dir " ${HELLO_BINARY_DIR})
-
MESSAGE( STATUS "This is SOURCE dir " ${HELLO_SOURCE_DIR})
-
add_definitions( -Dhha -Dbbb)
-
ADD_EXECUTABLE( hello ${SRC_LIST})
源代碼如下:
-
-
int main()
-
{
-
-
printf("include hhahah.\n");
-
-
-
printf("include bbbbbb.\n");
-
-
printf("hello,word.\n");
-
return 0;
-
}
輸出結果: