generated from LizardByte/template-base
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
111 lines (92 loc) · 3.23 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
cmake_minimum_required(VERSION 3.18)
# much of this file is borrowed from https://github.com/Ryzee119/Xenium-Tools/blob/master/CMakeLists.txt
# and https://github.com/abaire/nxdk_pgraph_tests/blob/main/CMakeLists.txt
project(Moonlight C CXX)
#
# metadata
#
set(XBE_TITLE ${CMAKE_PROJECT_NAME})
set(NXDK_DIR "${CMAKE_CURRENT_SOURCE_DIR}/third-party/nxdk")
set(XBOX_XBE_DIR "${CMAKE_CURRENT_BINARY_DIR}/xbe")
set(XBOX_ISO "${CMAKE_PROJECT_NAME}.iso")
#
# Options
#
option(BUILD_TESTS "Build tests" OFF)
# add custom modules
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/"
)
set(CMAKE_CXX_STANDARD 17)
find_package(NXDK REQUIRED)
find_package(NXDK_SDL2 REQUIRED)
find_package(NXDK_SDL2_Image REQUIRED)
# add the automount_d_drive symbol to the linker flags, this is automatic with nxdk when using the Makefile option
# if this is not used, we must add some code to the main function to automount the D drive
# e.g. https://github.com/abaire/nxdk_pgraph_tests/blob/4b7934e6d612a6d17f9ec229a2d72601a5caefc4/src/main.cpp#L118-L122
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -include:_automount_d_drive")
# create the xbe directory if it doesn't exist
file(MAKE_DIRECTORY ${XBOX_XBE_DIR})
# copy assets directory to xbe directory
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/xbe/" DESTINATION "${XBOX_XBE_DIR}")
include(FindPkgConfig)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
set(CMAKE_CXX_FLAGS_RELEASE "-O2")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(MOONLIGHT_SOURCES
"${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp"
)
set(MOONLIGHT_EXTERNAL_LIBRARIES
NXDK::NXDK
NXDK::NXDK_CXX
NXDK::SDL2
NXDK::SDL2_Image
)
set(MOONLIGHT_INCLUDE_DIRS
)
set(MOONLIGHT_COMPILE_OPTIONS "-Wno-builtin-macro-redefined")
set(MOONLIGHT_DEFINITIONS "-DXBOX -DNXDK")
# Stop lots of warning spam
add_compile_options(${MOONLIGHT_COMPILE_OPTIONS})
add_definitions(${MOONLIGHT_DEFINITIONS})
add_executable(${CMAKE_PROJECT_NAME}
${MOONLIGHT_SOURCES}
)
include_directories(SYSTEM
${CMAKE_CURRENT_SOURCE_DIR}
${MOONLIGHT_INCLUDE_DIRS})
target_link_libraries(${CMAKE_PROJECT_NAME} PUBLIC
${MOONLIGHT_EXTERNAL_LIBRARIES}
)
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE "")
#
# tests
#
if(BUILD_TESTS)
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()
# Post-build exe to xbe conversion
add_custom_target(cxbe_convert ALL
VERBATIM COMMAND "${CMAKE_COMMAND}" -E env
./tools/cxbe/cxbe
-OUT:${XBOX_XBE_DIR}/default.xbe
-TITLE:${XBE_TITLE}
${CMAKE_CURRENT_BINARY_DIR}/${XBE_TITLE}.exe
WORKING_DIRECTORY ${NXDK_DIR}
COMMENT "CXBE Conversion: [EXE -> XBE]"
)
add_dependencies(cxbe_convert ${CMAKE_PROJECT_NAME})
# Post-build xbe to xiso conversion
add_custom_target(xbe_iso ALL
VERBATIM COMMAND "${CMAKE_COMMAND}" -E env
${NXDK_DIR}/tools/extract-xiso/build/extract-xiso
-c ${XBOX_XBE_DIR} ${XBOX_ISO}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "CXBE Conversion: [XBE -> XISO]"
)
add_dependencies(xbe_iso cxbe_convert)
set_target_properties(cxbe_convert PROPERTIES OUTPUT_QUIET ON)
set_target_properties(xbe_iso PROPERTIES OUTPUT_QUIET ON)