6
6
# CMake specifications
7
7
# -----------------------------------------------------------------------------
8
8
cmake_minimum_required (VERSION 3.16 )
9
- project (mlx42 VERSION 2.3.2 )
9
+ project (mlx42 VERSION 2.4.1 )
10
10
message (STATUS "MLX42 @ ${CMAKE_PROJECT_VERSION} " )
11
11
12
12
# Variables
@@ -34,14 +34,13 @@ set(BUILD_TESTS OFF CACHE BOOL "Build the tests to verify the integrity of the l
34
34
add_definitions (-D LODEPNG_NO_COMPILE_ENCODER )
35
35
add_definitions (-D LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS )
36
36
37
- if (UNIX )
38
- set (CCSHADER ${PROJECT_SOURCE_DIR} /tools/compile_shader.sh )
37
+ if (UNIX AND NOT EMSCRIPTEN )
39
38
add_compile_options (
40
39
-Wextra
41
40
-Wall
42
41
-Werror
43
42
-Wunreachable-code
44
-
43
+
45
44
# Some low priority warnings that are annoying.
46
45
-Wno-char-subscripts
47
46
-Wno-sign-compare
@@ -58,31 +57,44 @@ if(UNIX)
58
57
endif (DEBUG )
59
58
else ()
60
59
# TODO: Figure out what we need for windows.
61
- set (CCSHADER ${PROJECT_SOURCE_DIR} /tools/compile_shader.bat )
62
60
endif ()
63
61
64
62
# Build specific files
65
63
# @see https://cmake.org/cmake/help/latest/command/add_custom_command.html
66
64
# -----------------------------------------------------------------------------
67
65
66
+ if (UNIX )
67
+ set (CCSHADER ${TOOLS_DIR} /compile_shader.sh )
68
+ else ()
69
+ set (CCSHADER ${TOOLS_DIR} /compile_shader.bat )
70
+ endif ()
71
+
72
+ if (EMSCRIPTEN )
73
+ set (EMSCRIPTEN_VALUE 1 )
74
+ else ()
75
+ set (EMSCRIPTEN_VALUE 0 )
76
+ endif ()
77
+
78
+ # Add custom command for fragment shader
68
79
add_custom_command (
69
- COMMENT "Building fragment shader"
70
- DEPENDS ${PROJECT_SOURCE_DIR} /shaders/default.frag
71
- OUTPUT mlx_frag_shader.c
72
- COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR} /shaders/default.frag > mlx_frag_shader.c
73
- VERBATIM
74
- PRE_BUILD
75
- USES_TERMINAL
80
+ COMMENT "Building fragment shader"
81
+ DEPENDS ${PROJECT_SOURCE_DIR} /shaders/default.frag
82
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR} / mlx_frag_shader.c
83
+ COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR} /shaders/default.frag ${EMSCRIPTEN_VALUE} > ${CMAKE_CURRENT_BINARY_DIR} / mlx_frag_shader.c
84
+ VERBATIM
85
+ PRE_BUILD
86
+ USES_TERMINAL
76
87
)
77
88
89
+ # Add custom command for vertex shader
78
90
add_custom_command (
79
- COMMENT "Building vertex shader"
80
- DEPENDS ${PROJECT_SOURCE_DIR} /shaders/default.vert
81
- OUTPUT mlx_vert_shader.c
82
- COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR} /shaders/default.vert > mlx_vert_shader.c
83
- VERBATIM
84
- PRE_BUILD
85
- USES_TERMINAL
91
+ COMMENT "Building vertex shader"
92
+ DEPENDS ${PROJECT_SOURCE_DIR} /shaders/default.vert
93
+ OUTPUT ${CMAKE_CURRENT_BINARY_DIR} / mlx_vert_shader.c
94
+ COMMAND ${CCSHADER} ${PROJECT_SOURCE_DIR} /shaders/default.vert ${EMSCRIPTEN_VALUE} > ${CMAKE_CURRENT_BINARY_DIR} / mlx_vert_shader.c
95
+ VERBATIM
96
+ PRE_BUILD
97
+ USES_TERMINAL
86
98
)
87
99
88
100
# Sources
@@ -125,29 +137,32 @@ target_include_directories(mlx42 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
125
137
# Dependencies
126
138
# -----------------------------------------------------------------------------
127
139
128
- find_package (glfw3 )
129
140
find_package (OpenGL REQUIRED )
130
141
131
- target_link_libraries (mlx42 OpenGL::GL )
132
- if (NOT glfw3_FOUND AND GLFW_FETCH )
133
- message (STATUS "Install GLFW to suppress this message" )
134
- message (STATUS "Please wait, fetching GLFW ..." )
135
- include (${CMAKE_DIR} /LinkGLFW.cmake )
136
- LinkGLFW (mlx42 )
137
- elseif (NOT glfw3_FOUND AND NOT GLFW_FETCH )
138
- message (FATAL_ERROR "Unable to build: GLFW can't be found nor fetched." )
139
- endif ()
140
-
141
- if (glfw3_FOUND )
142
- target_link_libraries (mlx42 ${GLFW3_LIBRARY} )
143
- endif ()
144
- if (APPLE )
145
- target_link_libraries (mlx42 "-framework Cocoa" "-framework IOKit" )
142
+ if (EMSCRIPTEN )
143
+ target_link_libraries (mlx42 "-s USE_GLFW=3" "-s FULL_ES3=1" )
144
+ else ()
145
+ target_link_libraries (mlx42 OpenGL::GL )
146
+ find_package (glfw3 )
147
+ if (glfw3_FOUND )
148
+ target_link_libraries (mlx42 ${GLFW3_LIBRARY} )
149
+ endif ()
150
+ if (NOT glfw3_FOUND AND GLFW_FETCH )
151
+ message (STATUS "Install GLFW to suppress this message" )
152
+ message (STATUS "Please wait, fetching GLFW ..." )
153
+ include (${CMAKE_DIR} /LinkGLFW.cmake )
154
+ LinkGLFW (mlx42 )
155
+ elseif (NOT glfw3_FOUND AND NOT GLFW_FETCH )
156
+ message (FATAL_ERROR "Unable to build: GLFW can't be found nor fetched." )
157
+ endif ()
158
+ if (APPLE )
159
+ target_link_libraries (mlx42 "-framework Cocoa" "-framework IOKit" )
160
+ endif ()
146
161
endif ()
147
162
148
163
# Testing
149
164
# -----------------------------------------------------------------------------
150
- # Only build tests if we are the main project or explicitly told to, make sure
165
+ # Only build tests if we are the main project or explicitly told to, make sure
151
166
# tests are not built when mlx42 is included as a subproject, use MLX42_BUILD_TESTS to overwrite this
152
167
# use cmake -DBUILD_TESTS=ON/-DMLX42_BUILD_TESTS=ON to build tests
153
168
@@ -165,7 +180,7 @@ endif()
165
180
# This only really useful if you are a system administrator and want to install
166
181
# the library to the system, if you are a developer you should just use the
167
182
# library as a subproject as you probably don't have (nor really should) have any
168
- # amibitons to use this for anything other than your own school projects.
183
+ # ambitions to use this for anything other than your own school projects.
169
184
170
185
install (
171
186
DIRECTORY ./include/MLX42 DESTINATION ${CMAKE_INSTALL_PREFIX} /include
0 commit comments