2024-01-19 20:33:40 +08:00
|
|
|
include(${_AX_ROOT}/1k/platform.cmake)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
# custom target property for lua/js link
|
|
|
|
define_property(TARGET
|
2022-07-16 10:43:05 +08:00
|
|
|
PROPERTY AX_LUA_DEPEND
|
2022-10-18 19:13:40 +08:00
|
|
|
BRIEF_DOCS "axmol lua depend libs"
|
|
|
|
FULL_DOCS "use to save depend libs of axmol lua project"
|
2022-09-05 14:13:52 +08:00
|
|
|
)
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-03-14 08:24:27 +08:00
|
|
|
# UWP min deploy target support, VS property: targetPlatformMinVersion
|
|
|
|
if (WINRT)
|
|
|
|
if (NOT DEFINED AX_VS_DEPLOYMENT_TARGET)
|
|
|
|
set(AX_VS_DEPLOYMENT_TARGET "10.0.17763.0")
|
|
|
|
endif()
|
|
|
|
if("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}" VERSION_GREATER_EQUAL "3.27.0")
|
|
|
|
if (NOT DEFINED)
|
|
|
|
# The minmal deploy target version: Windows 10, version 1809 (Build 10.0.17763) for building msix package
|
|
|
|
# refer to: https://learn.microsoft.com/en-us/windows/msix/supported-platforms?source=recommendations
|
|
|
|
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION ${AX_VS_DEPLOYMENT_TARGET})
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
if(DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION)
|
|
|
|
unset(CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION)
|
|
|
|
endif()
|
|
|
|
endif()
|
2024-02-22 20:03:16 +08:00
|
|
|
set(AX_CPPWINRT_VERSION "2.0.240111.5" CACHE STRING "")
|
2023-03-14 08:24:27 +08:00
|
|
|
endif()
|
|
|
|
|
2020-08-30 13:48:12 +08:00
|
|
|
# config c standard
|
2023-07-01 21:11:01 +08:00
|
|
|
if (WINDOWS)
|
|
|
|
message(STATUS "CMAKE_HOST_SYSTEM_VERSION: ${CMAKE_HOST_SYSTEM_VERSION}")
|
|
|
|
message(STATUS "CMAKE_SYSTEM_VERSION: ${CMAKE_SYSTEM_VERSION}")
|
|
|
|
message(STATUS "CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}")
|
|
|
|
if (DEFINED CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION)
|
|
|
|
message(STATUS "CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION: ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_MIN_VERSION}")
|
|
|
|
endif()
|
|
|
|
if (NOT CMAKE_SYSTEM_VERSION)
|
|
|
|
set(CMAKE_SYSTEM_VERSION ${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION})
|
|
|
|
endif()
|
2024-01-22 21:46:55 +08:00
|
|
|
# Fix win32 llvm-clang
|
|
|
|
if (NOT CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION)
|
|
|
|
set(CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION ${CMAKE_SYSTEM_VERSION})
|
|
|
|
endif()
|
2024-01-20 16:16:53 +08:00
|
|
|
# CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION aka selected windows sdk version
|
|
|
|
if (${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} VERSION_GREATER_EQUAL "10.0.22000.0")
|
2023-07-01 21:11:01 +08:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
2023-01-03 15:09:45 +08:00
|
|
|
else()
|
2023-07-01 21:11:01 +08:00
|
|
|
# windows sdk < 10.0.22000.0, The c11 header stdalign.h was missing, so workaroud fallback C standard to 99
|
|
|
|
# refer to:
|
|
|
|
# - https://github.com/axmolengine/axmol/issues/991
|
|
|
|
# - https://github.com/axmolengine/axmol/issues/1246
|
|
|
|
message(WARNING "Forcing set CMAKE_C_STANDARD to 99 when winsdk < 10.0.22000.0")
|
|
|
|
set(CMAKE_C_STANDARD 99)
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
if(NOT DEFINED CMAKE_C_STANDARD)
|
2023-01-03 15:09:45 +08:00
|
|
|
set(CMAKE_C_STANDARD 11)
|
|
|
|
endif()
|
2023-09-02 20:17:39 +08:00
|
|
|
endif()
|
2022-12-20 11:31:52 +08:00
|
|
|
message(STATUS "CMAKE_C_STANDARD=${CMAKE_C_STANDARD}")
|
|
|
|
if(NOT DEFINED CMAKE_C_STANDARD_REQUIRED)
|
2020-08-30 13:48:12 +08:00
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
|
2023-09-26 00:11:33 +08:00
|
|
|
# config c++ standard, minimal require c++20
|
|
|
|
set(_AX_MIN_CXX_STD 20)
|
|
|
|
if (NOT DEFINED CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD ${_AX_MIN_CXX_STD})
|
|
|
|
endif()
|
|
|
|
if (CMAKE_CXX_STANDARD GREATER_EQUAL ${_AX_MIN_CXX_STD})
|
|
|
|
message(STATUS "Building axmol with c++${CMAKE_CXX_STANDARD}")
|
|
|
|
else()
|
|
|
|
message(STATUS "Building axmol require c++ std >= ${_AX_MIN_CXX_STD}")
|
2022-12-20 11:31:52 +08:00
|
|
|
endif()
|
2023-09-26 00:11:33 +08:00
|
|
|
set(_AX_CXX_STD ${CMAKE_CXX_STANDARD} CACHE STRING "" FORCE)
|
2022-12-20 11:31:52 +08:00
|
|
|
|
|
|
|
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
2020-08-18 11:41:42 +08:00
|
|
|
endif()
|
2022-12-20 11:31:52 +08:00
|
|
|
|
2023-06-13 20:30:57 +08:00
|
|
|
# check compiler on windows
|
|
|
|
if(WINDOWS)
|
|
|
|
# not support other compile tools except MSVC for now
|
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
|
|
|
|
message(STATUS "Using Windows clang generate axmol project, CLANG_VERSION: ${CLANG_VERSION_STRING}")
|
|
|
|
set(FUZZ_CLANG TRUE)
|
|
|
|
if (NOT MSVC)
|
|
|
|
set(FULL_CLANG TRUE)
|
|
|
|
else()
|
|
|
|
set(FUZZ_MSVC TRUE)
|
|
|
|
endif()
|
|
|
|
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
# Visual Studio 2015, MSVC_VERSION 1900 (v140 toolset)
|
|
|
|
# Visual Studio 2017, MSVC_VERSION 1910-1919 (v141 toolset)
|
|
|
|
set(FUZZ_MSVC TRUE)
|
|
|
|
set(FULL_MSVC TRUE)
|
|
|
|
if(${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
|
|
|
|
message(STATUS "Using Windows MSVC generate axmol project, MSVC_VERSION:${MSVC_VERSION}")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Using Windows MSVC generate axmol project, MSVC_VERSION:${MSVC_VERSION} lower than needed")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Please using Windows MSVC/LLVM-Clang compile axmol project")
|
|
|
|
endif()
|
|
|
|
endif()
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2023-12-21 23:59:24 +08:00
|
|
|
if(EMSCRIPTEN_VERSION)
|
|
|
|
message(STATUS "Using emsdk generate axmol project, EMSCRIPTEN_VERSION: ${EMSCRIPTEN_VERSION}")
|
|
|
|
endif()
|
|
|
|
|
2023-06-13 20:30:57 +08:00
|
|
|
if (FUZZ_MSVC)
|
2021-12-04 13:45:25 +08:00
|
|
|
add_compile_options(/GF)
|
|
|
|
endif()
|
|
|
|
|
2023-06-13 20:30:57 +08:00
|
|
|
if (FULL_MSVC)
|
|
|
|
add_compile_options(/Bv)
|
|
|
|
endif()
|
|
|
|
|
2021-05-12 11:18:31 +08:00
|
|
|
set(CMAKE_DEBUG_POSTFIX "" CACHE STRING "Library postfix for debug builds. Normally left blank." FORCE)
|
|
|
|
|
2022-04-04 17:47:45 +08:00
|
|
|
# set hash style to both for android old device compatible
|
2022-10-01 16:24:52 +08:00
|
|
|
# see also: https://github.com/axmolengine/axmol/discussions/614
|
2022-04-04 17:47:45 +08:00
|
|
|
if (ANDROID)
|
|
|
|
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--hash-style=both")
|
|
|
|
endif()
|
|
|
|
|
2020-11-10 14:36:55 +08:00
|
|
|
# Set macro definitions for special platforms
|
2022-08-08 18:02:17 +08:00
|
|
|
function(use_ax_compile_define target)
|
|
|
|
target_compile_definitions(${target} PUBLIC $<$<CONFIG:Debug>:_AX_DEBUG=1>)
|
2022-09-05 14:13:52 +08:00
|
|
|
|
2022-10-18 19:13:40 +08:00
|
|
|
# !important axmol not use double precision
|
2020-08-09 22:41:06 +08:00
|
|
|
# target_compile_definitions(${target} PUBLIC CP_USE_CGTYPES=0)
|
|
|
|
# target_compile_definitions(${target} PUBLIC CP_USE_DOUBLES=0)
|
2022-09-05 14:13:52 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
if(APPLE)
|
|
|
|
target_compile_definitions(${target} PUBLIC __APPLE__)
|
|
|
|
target_compile_definitions(${target} PUBLIC USE_FILE32API)
|
2023-09-02 19:56:50 +08:00
|
|
|
if(AX_USE_GL)
|
2022-09-05 14:13:52 +08:00
|
|
|
target_compile_definitions(${target}
|
2023-09-02 19:56:50 +08:00
|
|
|
PUBLIC AX_USE_GL=1
|
|
|
|
PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE}
|
2021-04-22 22:01:47 +08:00
|
|
|
PUBLIC GL_SILENCE_DEPRECATION=1
|
|
|
|
)
|
2020-08-28 12:57:00 +08:00
|
|
|
endif()
|
2019-11-23 20:27:39 +08:00
|
|
|
elseif(LINUX)
|
2023-06-10 22:05:49 +08:00
|
|
|
ax_config_pred(${target} AX_ENABLE_VLC_MEDIA)
|
2019-11-23 20:27:39 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
|
|
|
|
elseif(ANDROID)
|
2023-09-02 19:56:50 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
|
2019-11-23 20:27:39 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC USE_FILE32API)
|
2023-09-01 16:31:14 +08:00
|
|
|
elseif(EMSCRIPTEN)
|
2023-09-02 19:56:50 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
|
2019-11-23 20:27:39 +08:00
|
|
|
elseif(WINDOWS)
|
2023-09-02 19:56:50 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC AX_GLES_PROFILE=${AX_GLES_PROFILE})
|
2023-06-10 22:05:49 +08:00
|
|
|
ax_config_pred(${target} AX_ENABLE_VLC_MEDIA)
|
2022-09-05 14:13:52 +08:00
|
|
|
target_compile_definitions(${target}
|
2019-11-23 20:27:39 +08:00
|
|
|
PUBLIC WIN32
|
|
|
|
PUBLIC _WIN32
|
|
|
|
PUBLIC _WINDOWS
|
|
|
|
PUBLIC UNICODE
|
|
|
|
PUBLIC _UNICODE
|
|
|
|
PUBLIC _CRT_SECURE_NO_WARNINGS
|
|
|
|
PUBLIC _SCL_SECURE_NO_WARNINGS
|
2020-09-15 16:01:44 +08:00
|
|
|
# PUBLIC GLAD_GLAPI_EXPORT
|
2019-11-23 20:27:39 +08:00
|
|
|
)
|
|
|
|
if(BUILD_SHARED_LIBS)
|
2024-02-20 05:37:12 +08:00
|
|
|
target_compile_definitions(${target} PRIVATE AX_DLLEXPORT INTERFACE AX_DLLIMPORT)
|
2019-11-23 20:27:39 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2023-09-05 21:10:25 +08:00
|
|
|
# Set compiler options for engine lib: axmol
|
2022-08-08 18:02:17 +08:00
|
|
|
function(use_ax_compile_options target)
|
2023-04-01 23:11:58 +08:00
|
|
|
if (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
|
|
|
|
# Enable msvc multi-process building
|
|
|
|
target_compile_options(${target} PUBLIC /MP)
|
2023-09-05 21:10:25 +08:00
|
|
|
elseif(WASM)
|
|
|
|
# refer to: https://github.com/emscripten-core/emscripten/blob/main/src/settings.js
|
|
|
|
target_link_options(${target} PUBLIC -sFORCE_FILESYSTEM=1 -sFETCH=1 -sUSE_GLFW=3)
|
2019-11-23 20:27:39 +08:00
|
|
|
endif()
|
2020-11-10 14:36:55 +08:00
|
|
|
endfunction()
|
|
|
|
|
2023-09-01 16:31:14 +08:00
|
|
|
if(EMSCRIPTEN)
|
2024-03-11 01:22:07 +08:00
|
|
|
set(AX_WASM_THREADS "4" CACHE STRING "Wasm threads count")
|
2023-09-06 09:52:39 +08:00
|
|
|
|
|
|
|
set(_AX_WASM_THREADS_INT 0)
|
|
|
|
if (AX_WASM_THREADS STREQUAL "auto") # not empty string or not 0
|
2023-09-06 00:39:11 +08:00
|
|
|
# Enable pthread support globally
|
|
|
|
include(ProcessorCount)
|
2023-09-06 09:52:39 +08:00
|
|
|
ProcessorCount(_AX_WASM_THREADS_INT)
|
|
|
|
elseif(AX_WASM_THREADS MATCHES "^([0-9]+)$" OR AX_WASM_THREADS STREQUAL "navigator.hardwareConcurrency")
|
|
|
|
set(_AX_WASM_THREADS_INT ${AX_WASM_THREADS})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
message(STATUS "AX_WASM_THREADS=${AX_WASM_THREADS}")
|
|
|
|
message(STATUS "_AX_WASM_THREADS_INT=${_AX_WASM_THREADS_INT}")
|
|
|
|
|
|
|
|
if (_AX_WASM_THREADS_INT)
|
2023-09-06 00:39:11 +08:00
|
|
|
add_compile_options(-pthread)
|
2023-09-06 09:52:39 +08:00
|
|
|
add_link_options(-pthread -sPTHREAD_POOL_SIZE=${_AX_WASM_THREADS_INT})
|
2023-09-06 00:39:11 +08:00
|
|
|
endif()
|
2023-09-05 21:10:25 +08:00
|
|
|
|
|
|
|
# Tell emcc build port libs in cache with compiler flag `-pthread` xxx.c.o
|
|
|
|
# must via CMAKE_C_FLAGS and CMAKE_CXX_FLAGS?
|
|
|
|
set(_AX_EMCC_FLAGS "-sUSE_LIBJPEG=1 -sUSE_ZLIB=1")
|
|
|
|
|
|
|
|
set(CMAKE_C_FLAGS ${_AX_EMCC_FLAGS})
|
|
|
|
set(CMAKE_CXX_FLAGS ${_AX_EMCC_FLAGS})
|
2023-09-01 16:31:14 +08:00
|
|
|
endif()
|
|
|
|
|
2020-11-11 10:31:41 +08:00
|
|
|
# Try enable asm & nasm compiler support
|
|
|
|
set(can_use_assembler TRUE)
|
|
|
|
enable_language(ASM)
|
2020-11-11 13:27:52 +08:00
|
|
|
enable_language(ASM_NASM OPTIONAL)
|
2020-11-11 10:31:41 +08:00
|
|
|
|
2020-11-11 13:51:34 +08:00
|
|
|
if(NOT EXISTS "${CMAKE_ASM_NASM_COMPILER}")
|
|
|
|
set(CMAKE_ASM_NASM_COMPILER_LOADED FALSE CACHE BOOL "Does cmake asm nasm compiler loaded" FORCE)
|
2023-03-11 22:10:18 +08:00
|
|
|
message(WARNING "The nasm compiler doesn't present on your system PATH, please download from: https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/")
|
2020-11-11 10:31:41 +08:00
|
|
|
endif()
|
2024-02-01 22:40:37 +08:00
|
|
|
|
|
|
|
# we don't need cmake BUILD_TESTING feature
|
|
|
|
set(BUILD_TESTING FALSE CACHE BOOL "" FORCE)
|