|
| 1 | +cmake_minimum_required(VERSION 3.15) |
| 2 | +project(SimpleGraphic C CXX) |
| 3 | +set(CMAKE_CXX_STANDARD_REQUIRED ON) |
| 4 | +set(CMAKE_CXX_STANDARD 17) |
| 5 | + |
| 6 | +if (APPLE) |
| 7 | + enable_language(OBJCXX) |
| 8 | +endif () |
| 9 | + |
| 10 | +if (MSVC) |
| 11 | + add_compile_options("/Zi") |
| 12 | + add_link_options("/DEBUG:FULL") |
| 13 | +endif () |
| 14 | + |
| 15 | +list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") |
| 16 | + |
| 17 | +include(${PROJECT_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake) |
| 18 | + |
| 19 | +set(CMAKE_INSTALL_SYSTEM_RUNTIME_DESTINATION ".") |
| 20 | +include(InstallRequiredSystemLibraries) |
| 21 | + |
| 22 | +set(SIMPLEGRAPHIC_SOURCES |
| 23 | + "config.h" |
| 24 | + "dep/stb/stb_image.h" |
| 25 | + "dep/stb/stb_image_write.h" |
| 26 | + "engine/common/common.cpp" |
| 27 | + "engine/common/console.cpp" |
| 28 | + "engine/common/console.h" |
| 29 | + "engine/common/keylist.h" |
| 30 | + "engine/common/memtrak3.cpp" |
| 31 | + "engine/common/memtrak3.h" |
| 32 | + "engine/common/streams.cpp" |
| 33 | + "engine/common/streams.h" |
| 34 | + "engine/core/core_config.cpp" |
| 35 | + "engine/core/core_config.h" |
| 36 | + "engine/core/core_image.cpp" |
| 37 | + "engine/core/core_image.h" |
| 38 | + "engine/core/core_main.cpp" |
| 39 | + "engine/core/core_main.h" |
| 40 | + "engine/core/core_video.cpp" |
| 41 | + "engine/core/core_video.h" |
| 42 | + "engine/render/r_font.cpp" |
| 43 | + "engine/render/r_font.h" |
| 44 | + "engine/render/r_main.cpp" |
| 45 | + "engine/render/r_main.h" |
| 46 | + "engine/render/r_texture.cpp" |
| 47 | + "engine/render/r_texture.h" |
| 48 | + # "engine/system/win/sys_console.cpp" |
| 49 | + "engine/system/win/sys_console_unix.cpp" |
| 50 | + "engine/system/win/sys_local.h" |
| 51 | + "engine/system/win/sys_main.cpp" |
| 52 | + "engine/system/win/sys_opengl.cpp" |
| 53 | + "engine/system/win/sys_video.cpp" |
| 54 | + "engine/system/sys_console.h" |
| 55 | + "engine/system/sys_main.h" |
| 56 | + "engine/system/sys_opengl.h" |
| 57 | + "engine/system/sys_video.h" |
| 58 | + "win/entry.cpp" |
| 59 | + "ui.h" |
| 60 | + "ui_api.cpp" |
| 61 | + "ui_console.cpp" |
| 62 | + "ui_console.h" |
| 63 | + "ui_debug.cpp" |
| 64 | + "ui_debug.h" |
| 65 | + "ui_local.h" |
| 66 | + "ui_main.cpp" |
| 67 | + "ui_main.h" |
| 68 | + "ui_subscript.cpp" |
| 69 | + "ui_subscript.h" |
| 70 | +) |
| 71 | + |
| 72 | +set (SIMPLEGRAPHIC_PLATFORM_SOURCES) |
| 73 | +if (APPLE) |
| 74 | + set (SIMPLEGRAPHIC_PLATFORM_SOURCES |
| 75 | + "engine/system/win/sys_macos.mm" |
| 76 | + ) |
| 77 | +endif() |
| 78 | + |
| 79 | +add_library(SimpleGraphic SHARED |
| 80 | + ${SIMPLEGRAPHIC_SOURCES} |
| 81 | + ${SIMPLEGRAPHIC_PLATFORM_SOURCES} |
| 82 | +) |
| 83 | +target_compile_definitions(SimpleGraphic |
| 84 | + PRIVATE |
| 85 | + "UNICODE" |
| 86 | + "_CRT_SECURE_NO_DEPRECATE" |
| 87 | + "_CRT_SECURE_NO_WARNINGS" |
| 88 | + "_SCL_SECURE_NO_DEPRECATE" |
| 89 | + "_SCL_SECURE_NO_WARNINGS" |
| 90 | + "GLFW_INCLUDE_NONE" |
| 91 | + "GL_SILENCE_DEPRECATION" |
| 92 | + "SIMPLEGRAPHIC_EXPORTS" |
| 93 | +) |
| 94 | + |
| 95 | +target_include_directories(SimpleGraphic |
| 96 | + PUBLIC |
| 97 | + "${CMAKE_CURRENT_SOURCE_DIR}" |
| 98 | + "${CMAKE_CURRENT_SOURCE_DIR}/engine" |
| 99 | +) |
| 100 | + |
| 101 | +find_package(unofficial-angle CONFIG REQUIRED) |
| 102 | +find_package(CURL CONFIG REQUIRED) |
| 103 | +find_package(fmt CONFIG REQUIRED) |
| 104 | +find_package(glfw3 CONFIG REQUIRED) |
| 105 | +find_package(LuaJit REQUIRED) |
| 106 | +find_package(re2 CONFIG REQUIRED) |
| 107 | +find_package(unofficial-sodium CONFIG REQUIRED) |
| 108 | +find_package(Threads REQUIRED) |
| 109 | +find_package(ZLIB REQUIRED) |
| 110 | + |
| 111 | +add_library(imgui STATIC |
| 112 | + dep/imgui/imconfig.h |
| 113 | + dep/imgui/imgui.cpp |
| 114 | + dep/imgui/imgui.h |
| 115 | + dep/imgui/imgui_demo.cpp |
| 116 | + dep/imgui/imgui_draw.cpp |
| 117 | + dep/imgui/imgui_internal.h |
| 118 | + dep/imgui/imgui_tables.cpp |
| 119 | + dep/imgui/imgui_widgets.cpp |
| 120 | + dep/imgui/imstb_rectpack.h |
| 121 | + dep/imgui/imstb_textedit.h |
| 122 | + dep/imgui/imstb_truetype.h |
| 123 | + dep/imgui/backends/imgui_impl_glfw.cpp |
| 124 | + dep/imgui/backends/imgui_impl_glfw.h |
| 125 | + dep/imgui/backends/imgui_impl_opengl3.cpp |
| 126 | + dep/imgui/backends/imgui_impl_opengl3.h |
| 127 | + dep/imgui/backends/imgui_impl_opengl3_loader.h |
| 128 | + dep/imgui/misc/cpp/imgui_stdlib.cpp |
| 129 | + dep/imgui/misc/cpp/imgui_stdlib.h |
| 130 | +) |
| 131 | + |
| 132 | +target_compile_definitions(imgui PUBLIC |
| 133 | + "IMGUI_IMPL_OPENGL_ES2" |
| 134 | +) |
| 135 | + |
| 136 | +target_include_directories(imgui PUBLIC |
| 137 | + dep/imgui |
| 138 | + dep/imgui/backends |
| 139 | +) |
| 140 | + |
| 141 | +target_link_libraries(imgui PUBLIC |
| 142 | + unofficial::angle::libGLESv2 |
| 143 | + glfw |
| 144 | +) |
| 145 | + |
| 146 | +target_include_directories(SimpleGraphic |
| 147 | + PRIVATE |
| 148 | + ${CMAKE_CURRENT_SOURCE_DIR}/dep/glad/include |
| 149 | + ${CMAKE_CURRENT_SOURCE_DIR}/dep/stb |
| 150 | + ${JPEG_INCLUDE_DIR} |
| 151 | + ${LUAJIT_INCLUDE_DIR} |
| 152 | +) |
| 153 | + |
| 154 | +if (CMAKE_SYSTEM_NAME MATCHES "Linux") |
| 155 | + target_link_options(SimpleGraphic |
| 156 | + PRIVATE |
| 157 | + "-export-dynamic" |
| 158 | + ) |
| 159 | +endif () |
| 160 | + |
| 161 | +if (WIN32) |
| 162 | + target_link_libraries(SimpleGraphic |
| 163 | + PRIVATE |
| 164 | + "winmm.lib" |
| 165 | + ) |
| 166 | +endif () |
| 167 | + |
| 168 | +if (APPLE) |
| 169 | + find_library(CORE_FOUNDATION_LIBRARY CoreFoundation) |
| 170 | + find_library(APPLICATION_SERVICES_LIBRARY ApplicationServices) |
| 171 | + target_link_libraries(SimpleGraphic |
| 172 | + PRIVATE |
| 173 | + ${CORE_FOUNDATION_LIBRARY} |
| 174 | + ${APPLICATION_SERVICES_LIBRARY} |
| 175 | + ) |
| 176 | +endif () |
| 177 | + |
| 178 | +target_link_libraries(SimpleGraphic |
| 179 | + PRIVATE |
| 180 | + unofficial::angle::libEGL |
| 181 | + unofficial::angle::libGLESv2 |
| 182 | + fmt::fmt |
| 183 | + glfw |
| 184 | + imgui |
| 185 | + ${LUAJIT_LIBRARIES} |
| 186 | + re2::re2 |
| 187 | + unofficial-sodium::sodium |
| 188 | + Threads::Threads |
| 189 | + ZLIB::ZLIB |
| 190 | +) |
| 191 | + |
| 192 | +install(FILES $<TARGET_RUNTIME_DLLS:SimpleGraphic> DESTINATION ".") |
| 193 | +install(TARGETS SimpleGraphic RUNTIME DESTINATION ".") |
| 194 | + |
| 195 | +if (WIN32) |
| 196 | + if (DEFINED ENV{DEPS_DIR}) |
| 197 | + set(DEPS_BIN_DIR ${DEPS_DIR}/bin) |
| 198 | + else () |
| 199 | + set(DEPS_BIN_DIR "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin") |
| 200 | + endif () |
| 201 | + find_file(LUAJIT_DLL NAMES "lua51.dll" PATHS "${DEPS_BIN_DIR}" REQUIRED) |
| 202 | + find_file(ZLIB_DLL NAMES "zlib1.dll" PATHS "${DEPS_BIN_DIR}" REQUIRED) |
| 203 | + install(FILES ${LUAJIT_DLL} ${ZLIB_DLL} DESTINATION ".") |
| 204 | +endif () |
| 205 | + |
| 206 | + |
| 207 | +# lcurl module |
| 208 | + |
| 209 | +set(LCURL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/libs/Lua-cURLv3) |
| 210 | +file(GLOB LCURL_SOURCES ${LCURL_SOURCE_DIR}/src/**.c) |
| 211 | +add_library(lcurl SHARED ${LCURL_SOURCES}) |
| 212 | + |
| 213 | +target_include_directories(lcurl |
| 214 | + PRIVATE |
| 215 | + ${LCURL_SOURCE_DIR}/src |
| 216 | + ${LUAJIT_INCLUDE_DIR} |
| 217 | +) |
| 218 | + |
| 219 | +target_link_libraries(lcurl |
| 220 | + PRIVATE |
| 221 | + CURL::libcurl |
| 222 | + ${LUAJIT_LIBRARIES} |
| 223 | +) |
| 224 | + |
| 225 | +install(TARGETS lcurl RUNTIME DESTINATION ".") |
| 226 | +install(FILES $<TARGET_RUNTIME_DLLS:lcurl> DESTINATION ".") |
| 227 | + |
| 228 | + |
| 229 | +# lzip module |
| 230 | + |
| 231 | +add_library(lzip SHARED libs/LZip/lzip.cpp) |
| 232 | + |
| 233 | +target_include_directories(lzip |
| 234 | + PRIVATE |
| 235 | + ${LUAJIT_INCLUDE_DIR} |
| 236 | +) |
| 237 | + |
| 238 | +target_link_libraries(lzip |
| 239 | + PRIVATE |
| 240 | + ${LUAJIT_LIBRARIES} |
| 241 | + ZLIB::ZLIB |
| 242 | +) |
| 243 | + |
| 244 | +install(TARGETS lzip RUNTIME DESTINATION ".") |
| 245 | +install(FILES $<TARGET_RUNTIME_DLLS:lzip> DESTINATION ".") |
0 commit comments