-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
159 lines (141 loc) · 3.92 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
# Copyright (C) 2021 Ben Smith
#
# This software may be modified and distributed under the terms
# of the MIT license. See the LICENSE file for details.
cmake_minimum_required(VERSION 3.0)
project(binjnes)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
option(WERROR "Build with warnings as errors" OFF)
option(WASM_SIMD "Use SIMD" OFF)
if (UNIX AND NOT APPLE)
set(LINUX TRUE)
endif ()
include(CheckIncludeFile)
CHECK_INCLUDE_FILE("stdatomic.h" HAVE_C11_ATOMIC)
CHECK_INCLUDE_FILE("threads.h" HAVE_C11_THREADS)
CHECK_INCLUDE_FILE("pthread.h" HAVE_PTHREADS)
if (HAVE_C11_THREADS)
add_definitions(-DBINJNES_THREAD_C11)
elseif (HAVE_PTHREADS)
add_definitions(-DBINJNES_THREAD_PTHREADS)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-DBINJNES_THREAD_WIN32)
else ()
message(WARNING "No thread library found")
endif ()
if (HAVE_C11_ATOMIC)
add_definitions(-DBINJNES_ATOMIC_C11)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(-DBINJNES_ATOMIC_MSVC)
else ()
message(WARNING "No atomic library found")
endif ()
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_definitions(-DBINJNES_CLANG)
elseif (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
add_definitions(-DBINJNES_GCC)
endif ()
add_definitions(
-Wall -Wextra -Wpointer-arith -Wno-unused-parameter -g
-Wno-unused-function -Wno-unused-variable
-Wno-implicit-fallthrough -Wno-unknown-pragmas
)
if (WERROR)
add_definitions(-Werror)
endif ()
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
add_definitions(
/DBINJNES_MSVC
/D_CRT_SECURE_NO_WARNINGS
/std:c11
/wd4146 # unary minus operator applied to unsigned type
/wd4098 # 'void' function returning a value
)
endif()
function (target_copy_to_bin name)
add_custom_target(${name}-copy-to-bin ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${PROJECT_SOURCE_DIR}/bin
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:${name}> ${PROJECT_SOURCE_DIR}/bin
DEPENDS ${name}
)
endfunction ()
if (NOT EMSCRIPTEN)
add_executable(binjnes-tester
src/common.c
src/cartdb.c
src/options.c
src/emulator.c
src/joypad.c
src/tester.c
)
install(TARGETS binjnes-tester DESTINATION bin)
target_copy_to_bin(binjnes-tester)
# Sokol stuff
if (LINUX)
set(OpenGL_GL_PREFERENCE GLVND)
find_package(OpenGL)
find_package(X11)
find_package(Threads)
find_package(ALSA)
endif()
add_executable(binjnes
src/binjnes.c
src/cartdb.c
src/common.c
src/emulator.c
src/joypad.c
src/options.c
src/rewind.c
src/sokol.c
)
target_include_directories(binjnes
PUBLIC ${PROJECT_SOURCE_DIR}/third_party)
if (LINUX)
target_link_libraries(binjnes
OpenGL::GL
${X11_X11_LIB}
${X11_Xi_LIB}
${X11_Xcursor_LIB}
ALSA::ALSA
Threads::Threads
)
endif ()
install(TARGETS binjnes DESTINATION bin)
target_copy_to_bin(binjnes)
else (EMSCRIPTEN)
add_definitions(-Wno-format-security)
add_executable(binjnes
src/memory.c
src/cartdb.c
src/emulator.c
src/joypad.c
src/rewind.c
src/emscripten/wrapper.c)
set(EXPORTED_JSON ${PROJECT_SOURCE_DIR}/src/emscripten/exported.json)
target_include_directories(binjnes PUBLIC ${PROJECT_SOURCE_DIR}/src)
if (WASM_SIMD)
set(EXPORT_NAME "BinjnesSimd")
set_target_properties(binjnes PROPERTIES OUTPUT_NAME "binjnes-simd")
target_compile_options(binjnes PUBLIC -msimd128)
else ()
set(EXPORT_NAME "Binjnes")
endif ()
set(LINK_FLAGS
--memory-init-file 0
-s EXPORTED_FUNCTIONS=\"@${EXPORTED_JSON}\"
-s MALLOC=emmalloc
-s ASSERTIONS=0
-s ENVIRONMENT=web
-s FILESYSTEM=0
-s EXIT_RUNTIME=0
-s MODULARIZE=1
-s EXPORT_NAME="${EXPORT_NAME}"
)
string(REPLACE ";" " " LINK_FLAGS_STR "${LINK_FLAGS}")
set_target_properties(binjnes
PROPERTIES
LINK_FLAGS "${LINK_FLAGS_STR}"
LINK_DEPENDS "${EXPORTED_JSON}"
)
endif ()