MESSAGE(${CMAKE_SYSTEM}) # CMAKE_SYSTEM 表示系统版本号, 如Linux-3.13.0-30-generic
IF(CMAKE_SYSTEM MATCHES "Linux") #MATCHES和EQUAL都是IF的两个匹配方式,MATCHES更霸气。
Message(STATUS "equal is not matches")
ENDIF(CMAKE_SYSTEM MATCHES "Linux")
INCLUDE (CheckIncludeFiles) #C于cmake中的include,含义一致。 这里打开了/usr/share/cmake-2.8/Modules/CheckIncludeFile.cmake文件,其实它的内容就是一个以MACRO和ENDMACRO宏包围起来的一堆命令。
CHECK_INCLUDE_FILES(pthread.h PROJECT_HAVE_PTHREAD_H) #功能就像MACRO 的名字CHECK_INCLUDE_FILES一样。
IF(PROJECT_HAVE_PTHREAD_H)
MESSAGE(STATUS "HAVE_PTHREAD_H")
ENDIF(PROJECT_HAVE_PTHREAD_H)
set(CMAKE_HAVE_THREADS_LIBRARY) #相当于初始化该变量.
MESSAGE(STATUS ${CMAKE_FILES_DIRECTORY}) # ${CMAKE_FILES_DIRECTORY} == /CMakeFiles
#if("${VARIABLE}" MATCHES "^${VARIABLE}$") # 每个宏的开头和结尾都有这个,为什么?
INCLUDE (CheckSymbolExists)
INCLUDE (CheckLibraryExists)
CHECK_SYMBOL_EXISTS(printf stdio.h CMAKE_HAVE_LIBC_STDIO_PRINTF) #确保,printf函数在stdio.h中被声明,且是libc当中。
IF(CMAKE_HAVE_LIBC_STDIO_PRINTF)
MESSAGE(STATUS "HAVE PTHREAD_STDIO_PRINTF func")
ENDIF(CMAKE_HAVE_LIBC_STDIO_PRINTF)
# 与上面的语法一致,但是IF语句并没有被执行,应该时因为pthread是一个独立的第三方库。不再libc当中。
CHECK_SYMBOL_EXISTS(pthread_create
pthread.h CMAKE_HAVE_LIBC_CREATE)
IF(CMAKE_HAVE_LIBC_CREATE)
MESSAGE(STATUS "HAVE PTHREAD_CREATE func")
ENDIF(CMAKE_HAVE_LIBC_CREATE)
# 正确的做法如下:
CHECK_LIBRARY_EXISTS(pthread pthread_create "" CMAKE_HAVE_PTHREAD_CREATE)
if(CMAKE_HAVE_PTHREAD_CREATE)
MESSAGE("---------HAVE CMAKE_HAVE_PTHREADS_CREATE func")
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
set(CMAKE_HAVE_THREADS_LIBRARY 1)
set(Threads_FOUND TRUE)
endif()
阅读(2244) | 评论(0) | 转发(0) |