2019-11-23 20:27:39 +08:00
|
|
|
If(APPLE)
|
|
|
|
if(${CMAKE_VERSION} VERSION_LESS "3.14")
|
|
|
|
message(FATAL_ERROR "Please use CMake 3.14 or newer for Apple platform (macOS, iOS, tvOS or watchOS)")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
#Please use them everywhere
|
|
|
|
#WINDOWS = Windows Desktop
|
|
|
|
#ANDROID = Android
|
|
|
|
#IOS = iOS
|
|
|
|
#MACOSX = MacOS X
|
|
|
|
#LINUX = Linux
|
|
|
|
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
|
|
|
|
set(WINDOWS TRUE)
|
2021-09-01 10:28:37 +08:00
|
|
|
if(NOT ("${CMAKE_GENERATOR_PLATFORM}" STREQUAL "Win32"))
|
2021-08-26 23:25:17 +08:00
|
|
|
set(WIN64 TRUE)
|
2021-08-27 12:34:24 +08:00
|
|
|
set(ARCH_ALIAS "x64")
|
2021-08-26 23:25:17 +08:00
|
|
|
else()
|
|
|
|
set(WIN32 TRUE)
|
2021-08-27 12:34:24 +08:00
|
|
|
set(ARCH_ALIAS "x86")
|
2021-08-26 23:25:17 +08:00
|
|
|
endif()
|
2019-11-23 20:27:39 +08:00
|
|
|
set(PLATFORM_FOLDER win32)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Android")
|
|
|
|
set(PLATFORM_FOLDER android)
|
2022-06-17 22:16:55 +08:00
|
|
|
set(ARCH_ALIAS ${ANDROID_ABI})
|
2019-11-23 20:27:39 +08:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|
|
|
if(ANDROID)
|
|
|
|
set(PLATFORM_FOLDER android)
|
|
|
|
else()
|
|
|
|
set(LINUX TRUE)
|
|
|
|
set(PLATFORM_FOLDER linux)
|
|
|
|
endif()
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
set(APPLE TRUE)
|
|
|
|
set(MACOSX TRUE)
|
|
|
|
set(PLATFORM_FOLDER mac)
|
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "iOS")
|
|
|
|
set(APPLE TRUE)
|
|
|
|
set(IOS TRUE)
|
|
|
|
set(PLATFORM_FOLDER ios)
|
2022-09-05 14:13:52 +08:00
|
|
|
elseif(${CMAKE_SYSTEM_NAME} MATCHES "tvOS")
|
|
|
|
set(APPLE TRUE)
|
|
|
|
set(IOS TRUE)
|
|
|
|
set(TVOS TRUE)
|
|
|
|
set(PLATFORM_FOLDER tvos)
|
2019-11-23 20:27:39 +08:00
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported platform, CMake will exit")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# generators that are capable of organizing into a hierarchy of folders
|
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
# simplify generator condition, please use them everywhere
|
|
|
|
if(CMAKE_GENERATOR STREQUAL Xcode)
|
|
|
|
set(XCODE TRUE)
|
|
|
|
elseif(CMAKE_GENERATOR MATCHES Visual)
|
|
|
|
set(VS TRUE)
|
|
|
|
endif()
|
|
|
|
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
|
|
|
|
|
|
|
|
# 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
|
|
|
|
2020-08-30 13:48:12 +08:00
|
|
|
# config c standard
|
|
|
|
if (NOT WINDOWS)
|
|
|
|
if(NOT DEFINED C_STD)
|
|
|
|
set(C_STD 11)
|
|
|
|
endif()
|
|
|
|
message(STATUS "C_STD=${C_STD}")
|
|
|
|
set(CMAKE_C_STANDARD ${C_STD})
|
|
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# config c++ standard
|
2020-08-18 11:41:42 +08:00
|
|
|
if(NOT DEFINED CXX_STD)
|
2022-10-06 08:50:39 +08:00
|
|
|
set(CXX_STD 20)
|
2020-08-18 11:41:42 +08:00
|
|
|
endif()
|
|
|
|
message(STATUS "CXX_STD=${CXX_STD}")
|
|
|
|
set(CMAKE_CXX_STANDARD ${CXX_STD})
|
2019-11-23 20:27:39 +08:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
2021-12-04 13:45:25 +08:00
|
|
|
if (MSVC)
|
|
|
|
add_compile_options(/GF)
|
|
|
|
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()
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
# check visual studio version
|
2020-11-10 14:36:55 +08:00
|
|
|
if(WINDOWS)
|
2019-11-23 20:27:39 +08:00
|
|
|
# not support other compile tools except MSVC for now
|
|
|
|
if(MSVC)
|
|
|
|
# Visual Studio 2015, MSVC_VERSION 1900 (v140 toolset)
|
|
|
|
# Visual Studio 2017, MSVC_VERSION 1910-1919 (v141 toolset)
|
|
|
|
if(${MSVC_VERSION} EQUAL 1900 OR ${MSVC_VERSION} GREATER 1900)
|
2022-10-18 19:13:40 +08:00
|
|
|
message(STATUS "using Windows MSVC generate axmol project, MSVC_VERSION:${MSVC_VERSION}")
|
2019-11-23 20:27:39 +08:00
|
|
|
else()
|
2022-10-18 19:13:40 +08:00
|
|
|
message(FATAL_ERROR "using Windows MSVC generate axmol project, MSVC_VERSION:${MSVC_VERSION} lower than needed")
|
2019-11-23 20:27:39 +08:00
|
|
|
endif()
|
|
|
|
else()
|
2022-10-18 19:13:40 +08:00
|
|
|
message(FATAL_ERROR "please using Windows MSVC compile axmol project, support other compile tools not yet")
|
2019-11-23 20:27:39 +08:00
|
|
|
endif()
|
|
|
|
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)
|
2022-02-17 17:11:17 +08:00
|
|
|
if(AX_USE_COMPAT_GL)
|
2022-09-05 14:13:52 +08:00
|
|
|
target_compile_definitions(${target}
|
|
|
|
PUBLIC AX_USE_COMPAT_GL=1
|
2021-04-22 22:01:47 +08:00
|
|
|
PUBLIC GL_SILENCE_DEPRECATION=1
|
|
|
|
)
|
2020-08-28 12:57:00 +08:00
|
|
|
endif()
|
2022-09-05 14:13:52 +08:00
|
|
|
|
|
|
|
if(IOS)
|
|
|
|
if(TVOS)
|
|
|
|
target_compile_definitions(${target} PUBLIC AX_TARGET_OS_TVOS)
|
|
|
|
else()
|
|
|
|
target_compile_definitions(${target} PUBLIC AX_TARGET_OS_IPHONE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
elseif(LINUX)
|
|
|
|
target_compile_definitions(${target} PUBLIC _GNU_SOURCE)
|
|
|
|
elseif(ANDROID)
|
|
|
|
target_compile_definitions(${target} PUBLIC USE_FILE32API)
|
|
|
|
elseif(WINDOWS)
|
2022-02-17 17:11:17 +08:00
|
|
|
if(AX_USE_COMPAT_GL)
|
|
|
|
target_compile_definitions(${target} PUBLIC AX_USE_COMPAT_GL=1)
|
2020-09-15 14:22:19 +08:00
|
|
|
endif()
|
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)
|
2022-09-05 14:13:52 +08:00
|
|
|
target_compile_definitions(${target}
|
2020-10-06 16:46:38 +08:00
|
|
|
PRIVATE _USRDLL
|
|
|
|
PRIVATE _USEGUIDLL # ui
|
2019-11-23 20:27:39 +08:00
|
|
|
)
|
|
|
|
else()
|
2022-07-16 10:43:05 +08:00
|
|
|
target_compile_definitions(${target} PUBLIC AX_STATIC)
|
2019-11-23 20:27:39 +08:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-11-10 14:36:55 +08:00
|
|
|
# Set compiler options
|
2022-08-08 18:02:17 +08:00
|
|
|
function(use_ax_compile_options target)
|
2019-11-23 20:27:39 +08:00
|
|
|
if(MSVC)
|
|
|
|
target_compile_options(${target}
|
|
|
|
PUBLIC /MP
|
|
|
|
)
|
|
|
|
endif()
|
2020-11-10 14:36:55 +08:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# softfp for android armv7a?
|
|
|
|
# if(ANDROID)
|
|
|
|
# if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
|
|
|
|
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mfloat-abi=softfp")
|
|
|
|
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfloat-abi=softfp")
|
|
|
|
# endif()
|
|
|
|
# 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
|
|
|
message(STATUS "The nasm compiler speed up libraries: jpeg(libjpeg-turbo)")
|
|
|
|
|
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)
|
2020-11-11 10:31:41 +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.15.05/")
|
|
|
|
endif()
|