-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathCMakeLists.txt
120 lines (104 loc) · 3.93 KB
/
CMakeLists.txt
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
set(PROJECT_NAME "ToyRTX")
#---------------------------------------
macro(SETUP_PROJECT MODE TARGET_NAME STR_TARGET_SOURCES STR_TARGET_LIBS)
string(REPLACE " " ";" LIST_TARGET_SOURCES ${STR_TARGET_SOURCES})
string(REPLACE " " ";" LIST_TARGET_LIBS ${STR_TARGET_LIBS})
if(${STR_TARGET_SOURCES} STREQUAL " ")
message(WARNING "Target [${TARGET_NAME}] has no source, so it won't be generated.")
else()
if(${MODE} STREQUAL "EXE")
add_executable( ${TARGET_NAME} ${LIST_TARGET_SOURCES})
set(INSTALL_DIR "bin")
elseif(${MODE} STREQUAL "LIB")
add_library(${TARGET_NAME} ${LIST_TARGET_SOURCES})
set(INSTALL_DIR "lib/${FOLDER_NAME}")
else()
message(FATAL_ERROR "Mode [${MODE}] is not supported, so target [TARGET_NAME] is not generated!")
set(MODE_NOTSUPPORT " ")
endif()
if(NOT DEFINED MODE_NOTSUPPORT)
if( NOT ${FOLDER_NAME} STREQUAL " ")
SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES FOLDER ${FOLDER_NAME})
endif()
if(NOT ${STR_TARGET_LIBS} STREQUAL " ")
target_link_libraries( ${TARGET_NAME} ${LIST_TARGET_LIBS} )
endif()
install (TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_DIR})
message(STATUS "Setup Project ${Mode} ${FOLDER_NAME}/[${TARGET_NAME}]")
endif()
endif()
endmacro(SETUP_PROJECT TARGET_NAME STR_TARGET_SOURCES STR_TARGET_LIBS)
#---------------------------------------
macro(ADD_ALL_SUBDIR)
file(GLOB _children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
set(_dirlist "")
foreach(_child ${_children})
if(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${_child})
list(APPEND _dirlist ${_child})
endif()
endforeach()
#SET(${result} ${dirlist})
foreach(_subdir ${_dirlist})
add_subdirectory(${_subdir})
endforeach()
endmacro(ADD_ALL_SUBDIR)
#---------------------------------------
macro(GET_DIR_NAME DIRNAME)
string(REGEX MATCH "([^/]*)$" TMP ${CMAKE_CURRENT_SOURCE_DIR})
set(${DIRNAME} ${TMP})
endmacro(GET_DIR_NAME DIRNAME)
#---------------------------------------
macro(INSTALL_SHADERS)
# copy shader files to build directory
file(GLOB SHADERS
"${CMAKE_CURRENT_SOURCE_DIR}/*.vs"
"${CMAKE_CURRENT_SOURCE_DIR}/*.fs"
"${CMAKE_CURRENT_SOURCE_DIR}/*.gs"
)
foreach(SHADER ${SHADERS})
string(REGEX MATCH "([^/]*)$" TMP ${SHADER})
add_custom_command(TARGET ${TARGET_NAME} PRE_BUILD COMMAND ${CMAKE_COMMAND} -E copy ${SHADER} "${CMAKE_SOURCE_DIR}/data/shaders/${FOLDER_NAME}/${DIRNAME}/${TMP}")
install(FILES ${SHADER} DESTINATION "data/shaders/${FOLDER_NAME}/${DIRNAME}")
endforeach(SHADER)
endmacro(INSTALL_SHADERS)
#---------------------------------------
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
cmake_minimum_required (VERSION 2.8)
cmake_policy(VERSION 2.8)
project (${PROJECT_NAME})
# The version number.
set (${PROJECT_NAME}_VERSION_MAJOR 1)
set (${PROJECT_NAME}_VERSION_MINOR 0)
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR})
configure_file(config/config.in ${CMAKE_SOURCE_DIR}/config/config.out)
install(FILES "${CMAKE_SOURCE_DIR}/config/config.out"
DESTINATION config)
configure_file(config/ROOT_PATH.h.in config/ROOT_PATH.h)
include_directories (
${PROJECT_SOURCE_DIR}/include
${CMAKE_BINARY_DIR}/config
# $ENV{XXX_INCLUDE_PATH}
# ...
)
link_directories (
${PROJECT_SOURCE_DIR}/lib
${PROJECT_SOURCE_DIR}/lib/CppUtil/Basic
${PROJECT_SOURCE_DIR}/lib/CppUtil/OpenGL
${PROJECT_SOURCE_DIR}/lib/CppUtil/RTX
# $ENV{XXX_LIB_PATH}
# ...
)
FIND_PACKAGE( OpenMP REQUIRED)
if(OPENMP_FOUND)
message("OPENMP FOUND")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
endif()
add_subdirectory (src)
include (InstallRequiredSystemLibraries)
set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/License.txt")
set (CPACK_PACKAGE_VERSION_MAJOR "${${PROJECT_NAME}_VERSION_MAJOR}")
set (CPACK_PACKAGE_VERSION_MINOR "${${PROJECT_NAME}_VERSION_MINOR}")
set (CPACK_PACKAGE_CONTACT "641614112@qq.com")
include (CPack)