-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
160 lines (143 loc) · 5.36 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
set(librw_MAINPROJECT ON)
if(DEFINED PROJECT_NAME)
set(librw_MAINPROJECT OFF)
endif()
cmake_minimum_required(VERSION 3.8)
project(librw
VERSION 0.0.1
LANGUAGES C CXX
)
set(librw_AUTHOR aap)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
if(WIN32)
set(LIBRW_PLATFORMS "NULL" "GL3" "D3D9")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
elseif(NINTENDO_SWITCH)
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/nx")
include(NXFunctions)
elseif(PS2)
set(LIBRW_PLATFORMS "PS2")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL OFF)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/ps2")
include(PS2Functions)
else()
set(LIBRW_PLATFORMS "NULL" "GL3")
set(LIBRW_PLATFORM_GL3_REQUIRES_OPENGL ON)
endif()
list(GET LIBRW_PLATFORMS 0 LIBRW_PLATFORM_DEFAULT)
set(LIBRW_PLATFORM "${LIBRW_PLATFORM_DEFAULT}" CACHE STRING "Platform")
set_property(CACHE LIBRW_PLATFORM PROPERTY STRINGS ${LIBRW_PLATFORMS})
message(STATUS "LIBRW_PLATFORM = ${LIBRW_PLATFORM} (choices=${LIBRW_PLATFORMS})")
set("LIBRW_PLATFORM_${LIBRW_PLATFORM}" ON)
if(NOT LIBRW_PLATFORM IN_LIST LIBRW_PLATFORMS)
message(FATAL_ERROR "Illegal LIBRW_PLATFORM=${LIBRW_PLATFORM}")
endif()
set(LIBRW_GL3_GFXLIBS "GLFW" "SDL2")
set(LIBRW_GL3_GFXLIB "GLFW" CACHE STRING "gfxlib for gl3")
set_property(CACHE LIBRW_GL3_GFXLIB PROPERTY STRINGS ${LIBRW_GL3_GFXLIBS})
if(LIBRW_PLATFORM_GL3)
message(STATUS "LIBRW_GL3_GFXLIB = ${LIBRW_GL3_GFXLIB} (choices=${LIBRW_GL3_GFXLIBS})")
endif()
if(NOT LIBRW_GL3_GFXLIB IN_LIST LIBRW_GL3_GFXLIBS)
message(FATAL_ERROR "Illegal LIBRW_GL3_GFXLIB=${LIBRW_GL3_GFXLIB}")
endif()
if(LIBRW_PLATFORM_PS2)
enable_language(DSM)
endif()
if(NOT COMMAND librw_platform_target)
function(librw_platform_target)
endfunction()
endif()
include(CMakeDependentOption)
option(LIBRW_TOOLS "Build librw tools" ${librw_MAINPROJECT})
option(LIBRW_INSTALL "Install librw files" ${librw_MAINPROJECT})
cmake_dependent_option(LIBRW_EXAMPLES "Build librw examples" ON "LIBRW_TOOLS;NOT LIBRW_PLATFORM_NULL" OFF)
if(LIBRW_INSTALL)
include(GNUInstallDirs)
set(LIBRW_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/librw")
endif()
add_subdirectory(src)
if(LIBRW_TOOLS AND NOT LIBRW_PLATFORM_PS2 AND NOT LIBRW_PLATFORM_NULL)
add_subdirectory(skeleton)
endif()
add_subdirectory(tools)
if(LIBRW_INSTALL)
include(CMakePackageConfigHelpers)
configure_package_config_file(cmake/librw-config.cmake.in librw-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_PREFIX}"
)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/librw-config.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
install(
EXPORT librw-targets NAMESPACE librw::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}"
)
if(LIBRW_GL3_GFXLIB STREQUAL "SDL2")
install(
FILES "${CMAKE_CURRENT_LIST_DIR}/cmake/FindSDL2.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake"
)
endif()
string(REPLACE "." ";" cmake_c_compiler_version_list "${CMAKE_C_COMPILER_VERSION}")
list(GET cmake_c_compiler_version_list 0 cmake_c_compiler_version_major)
string(TOLOWER "${LIBRW_PLATFORM}" librw_platform)
set(compiler)
set(os)
if(NOT LIBRW_PLATFORM STREQUAL "PS2")
if(MSVC)
set(compiler "-msvc${MSVC_VERSION}")
elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU")
set(compiler "-gcc${cmake_c_compiler_version_major}")
elseif(CMAKE_C_COMPILER_ID STREQUAL "Clang")
set(compiler "-clang${cmake_c_compiler_version_major}")
elseif(CMAKE_C_COMPILER_ID STREQUAL "AppleClang")
set(compiler "-appleclang${cmake_c_compiler_version_major}")
else()
set(compiler "-UNK")
message(WARNING "Unknown compiler. Created cpack package will be wrong. (override using cpack -P)")
endif()
endif()
if(LIBRW_PLATFORM_NULL)
set(platform "-null")
elseif(LIBRW_PLATFORM_PS2)
set(platform "-ps2")
elseif(LIBRW_PLATFORM_GL3)
if(LIBRW_GL3_GFXLIB STREQUAL "GLFW")
set(platform "-gl3-glfw")
else()
set(platform "-gl3-sdl2")
endif()
elseif(LIBRW_PLATFORM_D3D9)
set(platform "-d3d9")
endif()
if(NOT LIBRW_PLATFORM_PS2)
if(WIN32)
set(os "-win")
elseif(NINTENDO_SWITCH)
set(os "-switch")
elseif(PS2)
set(os "-ps2")
elseif(APPLE)
set(os "-apple")
elseif(UNIX)
set(os "-linux")
else()
set(compiler "-UNK")
message(WARNING "Unknown os. Created cpack package will be wrong. (override using cpack -P)")
endif()
endif()
set(CPACK_PACKAGE_NAME "${PROJECT_NAME}${platform}${os}${compiler}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A (partial) re-implementation of RenderWare Graphics")
set(CPACK_PACKAGE_VENDOR "aap")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CPACK_PACKAGE_NAME}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_GENERATOR "TXZ")
include(CPack)
endif()