-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.cmake
43 lines (39 loc) · 1.21 KB
/
common.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
macro(listsubdir result curdir)
file(GLOB children RELATIVE ${curdir} ${curdir}/*)
set(dirs "")
foreach(child ${children})
if(IS_DIRECTORY ${curdir}/${child} AND EXISTS ${curdir}/${child}/CMakeLists.txt)
list(APPEND dirs ${child})
endif()
endforeach()
set(${result} ${dirs})
endmacro()
macro(use_cxx11)
if (CMAKE_VERSION VERSION_LESS "3.1")
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set (CMAKE_CXX_FLAGS "--std=gnu++11 ${CMAKE_CXX_FLAGS}")
else ()
set (CMAKE_CXX_FLAGS "--std=c++11 ${CMAKE_CXX_FLAGS}")
endif ()
else ()
set (CMAKE_CXX_STANDARD 11)
endif ()
endmacro(use_cxx11)
macro(write_cpp_file filepath content)
if(NOT EXISTS ${filepath})
message(STATUS "write file: ${filepath}")
file(WRITE ${filepath} ${content})
else()
file(READ ${filepath} ORIGIN_CONTENT)
if(NOT ${content} STREQUAL ${ORIGIN_CONTENT})
message(STATUS "write file: ${filepath}")
file(WRITE ${filepath} ${content})
endif()
endif()
endmacro()
macro(auto_generate_title)
# 自动生成title.h文件
set(TITLE_FILE "${CMAKE_CURRENT_LIST_DIR}/title.h")
set(TITLE_CONTENT "//this file is auto generated by cmake\n#define APP_TITLE \"${CURRENT_DIR_NAME}\"\n")
write_cpp_file(${TITLE_FILE} ${TITLE_CONTENT})
endmacro()