-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCMakeLists.txt
122 lines (96 loc) · 3.85 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
cmake_minimum_required(VERSION 3.23)
include(CMakeToolsHelpers OPTIONAL)
include(ExternalProject)
set(CMAKE_VERBOSE_MAKEFILE ON CACHE BOOL "ON" FORCE) # debug helper
message(STATUS "\n\nINFO: Running CMake ${CMAKE_VERSION}\n\n")
# the following prevents launching a build in the source tree
set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)
# fatal error and message explaining this
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(STATUS "\n-- ###############################################\n")
message(STATUS "Please run the build outside of the source tree.\n\n")
message(STATUS "Hint: create a 'build' folder and run CMake from there..")
message(STATUS "###############################################\n\n")
message(FATAL_ERROR "Build launched in the source tree.")
endif()
# set time stamp of build
string(TIMESTAMP BUILD_TIMESTAMP UTC)
message(STATUS "Building for hardware type: ${HARDWARE_TYPE}")
message(STATUS "Using SDK: ${SDK_TYPE}")
# make sure the version is set
if(NOT BUILD_VERSION)
set(BUILD_VERSION 0.0.1)
endif()
message(STATUS "ROM version is: ${BUILD_VERSION}")
message(STATUS "Tweek Timestamp is: ${BUILD_TIMESTAMP}")
string(REPLACE "." ";" VERSION_LIST ${BUILD_VERSION})
list(GET VERSION_LIST 0 BUILD_VER_MAJOR)
list(GET VERSION_LIST 1 BUILD_VER_MINOR)
list(GET VERSION_LIST 2 BUILD_VER_REV)
project(BUILD-DEMO # rename for your ROM name
VERSION ${BUILD_VERSION}
LANGUAGES C ASM)
set( ELF_NAME ${PROJECT_NAME}.elf )
set( BIN_NAME ${PROJECT_NAME}.bin )
set( ROM_NAME ${PROJECT_NAME}.z64 )
set( LINKER_FILE_NAME "${LIBDRAGON_PREFIX}/ldscripts/n64.ld" )
set(ROM_HEADER ${LIBDRAGON_PREFIX}/headers/header)
add_executable( ${ELF_NAME}
# Add libs here:
#${LIBDRAGON_SOURCES}
#${FATFS_SOURCES}
)
target_compile_definitions( ${ELF_NAME} PUBLIC
ROM_VER_MAJOR=${BUILD_VER_MAJOR}
ROM_VER_MINOR=${BUILD_VER_MINOR}
ROM_VER_REV=${BUILD_VER_REV}
ROM_VER_TWEEK=${BUILD_TIMESTAMP}
FLASHCART_TARGET_TYPE=${HARDWARE_TYPE}
FLASHCART_TARGET_REVISION=${HARDWARE_REVISION}
)
target_sources( ${ELF_NAME}
PUBLIC
# Add your source files here:
${CMAKE_CURRENT_LIST_DIR}/src/main.c
)
# probably a better way to do this, but if you need to build for something that uses different compiler flags...
#SET_SOURCE_FILES_PROPERTIES(${CMAKE_CURRENT_LIST_DIR}/src/gscore.c PROPERTIES COMPILE_FLAGS -O0)
target_include_directories( ${ELF_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/inc
# Add extra includes from libs here:
#${LIBDRAGON_INCLUDE_DIRS}
#${FATFS_INCLUDE_DIRS}
)
target_link_directories( ${ELF_NAME}
PUBLIC
${CMAKE_CURRENT_LIST_DIR}/lib
)
set_target_properties( ${ELF_NAME}
PROPERTIES LINK_FLAGS "-T${LINKER_FILE_NAME}"
)
add_custom_command(TARGET ${ELF_NAME}
POST_BUILD
COMMAND ${CMAKE_OBJCOPY} ARGS -O binary ${ELF_NAME} ${BIN_NAME}
)
# if the toolchain is different, we need to handle it here, or push it to a module, or even the toolchain?!
if(TOOLCHAIN_LIBDRAGON)
# # FIXME: There is a regression with N64-Tool where it cannot overwrite an existing file.
# # This command is a workaround:
# add_custom_command(TARGET ${ELF_NAME}
# POST_BUILD # Delete the ROM file so it can be overwritten by N64Tool
# COMMAND DEL -F ${ROM_NAME}
# )
add_custom_command(TARGET ${ELF_NAME}
POST_BUILD # Make sure your ROM size is big enough... perhaps we could use "size" on the bin to check?
COMMAND ${N64_TOOL} ARGS -l 1M -t "${PROJECT_NAME}" -h ${ROM_HEADER} -o ${ROM_NAME} ${BIN_NAME}
)
add_custom_command(TARGET ${ELF_NAME}
POST_BUILD
COMMAND ${CHECKSUM_TOOL} ARGS ${ROM_NAME}
)
else() # add some other compilation flags
# show error?
endif(TOOLCHAIN_LIBDRAGON)
unset(TOOLCHAIN_LIBDRAGON CACHE) # <---- this is the important to make sure the next build succeeds!!