1
0
mirror of https://github.com/VCMP-SqMod/SqMod.git synced 2024-11-08 00:37:15 +01:00

Update CMakeLists.txt

This commit is contained in:
Sandu Liviu Catalin 2021-02-01 01:49:03 +02:00
parent 2a719c18c2
commit 8df5f03d7b

View File

@ -10,95 +10,100 @@ option(ENABLE_API21 "Build for 2.1 API." OFF)
option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF) option(FORCE_32BIT_BIN "Create a 32-bit executable binary if the compiler defaults to 64-bit." OFF)
# This option should only be available in certain conditions # This option should only be available in certain conditions
if(WIN32 AND MINGW) if(WIN32 AND MINGW)
option(COPY_DEPENDENCIES "Copy deppendent DLLs into the deps folder." OFF) option(COPY_DEPENDENCIES "Copy deppendent DLLs into the deps folder." OFF)
endif() endif()
# C++14 is mandatory
set(CPP_STD_NUMBER 14)
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
# C++ standard availability check # C++ standard availability check
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+")
check_cxx_compiler_flag(-std=c++20 HAVE_FLAG_STD_CXX20) # Specific flags
check_cxx_compiler_flag(-std=c++2a HAVE_FLAG_STD_CXX2A) set(CPP_STD_COMPILER_FLAG "-std=c++14")
if(HAVE_FLAG_STD_CXX20 OR HAVE_FLAG_STD_CXX2A) # Don't even bother with previous version
# We can use C++20 if(CPP_STD_NUMBER LESS 20 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
set(CPP_STD_NUMBER 20) check_cxx_compiler_flag(-std=c++20 HAVE_FLAG_STD_CXX20)
# Specific flags check_cxx_compiler_flag(-std=c++2a HAVE_FLAG_STD_CXX2A)
if (HAVE_FLAG_STD_CXX2A AND NOT HAVE_FLAG_STD_CXX20) if(HAVE_FLAG_STD_CXX20 OR HAVE_FLAG_STD_CXX2A)
set(CPP_STD_COMPILER_FLAG "-std=c++20") # We can use C++20
else() set(CPP_STD_NUMBER 20)
set(CPP_STD_COMPILER_FLAG "-std=c++2a") # Specific flags
endif() if (HAVE_FLAG_STD_CXX2A AND NOT HAVE_FLAG_STD_CXX20)
# Need these workarounds for older CMake set(CPP_STD_COMPILER_FLAG "-std=c++2a")
if(${CMAKE_VERSION} VERSION_LESS "3.8.0") else()
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0) set(CPP_STD_COMPILER_FLAG "-std=c++20")
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++20") endif()
set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++20") # Need these workarounds for older CMake
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a") if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 10.0)
set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a") set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++20")
endif() set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++20")
endif() elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
else() set(CMAKE_CXX20_STANDARD_COMPILE_OPTION "-std=c++2a")
check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17) set(CMAKE_CXX20_EXTENSION_COMPILE_OPTION "-std=gnu++2a")
check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z) endif()
if(HAVE_FLAG_STD_CXX17 OR HAVE_FLAG_STD_CXX1Z) endif()
# We can use C++17 endif()
set(CPP_STD_NUMBER 17) endif()
# Specific flags # Don't even bother with previous version
if (HAVE_FLAG_STD_CXX17 AND NOT HAVE_FLAG_STD_CXX1Z) if(CPP_STD_NUMBER LESS 17 AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0)
set(CPP_STD_COMPILER_FLAG "-std=c++17") check_cxx_compiler_flag(-std=c++17 HAVE_FLAG_STD_CXX17)
else() check_cxx_compiler_flag(-std=c++1z HAVE_FLAG_STD_CXX1Z)
set(CPP_STD_COMPILER_FLAG "-std=c++1z") if(HAVE_FLAG_STD_CXX17 OR HAVE_FLAG_STD_CXX1Z)
endif() # We can use C++17
# Need these workarounds for older CMake set(CPP_STD_NUMBER 17)
if(${CMAKE_VERSION} VERSION_LESS "3.8.0") # Specific flags
if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0) if (HAVE_FLAG_STD_CXX1Z AND NOT HAVE_FLAG_STD_CXX17)
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17") set(CPP_STD_COMPILER_FLAG "-std=c++1z")
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17") else()
elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1) set(CPP_STD_COMPILER_FLAG "-std=c++17")
set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z") endif()
set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z") # Need these workarounds for older CMake
endif() if(${CMAKE_VERSION} VERSION_LESS "3.8.0")
endif() if (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0)
else() set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++17")
# C++14 is mandatory set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++17")
set(CPP_STD_NUMBER 14) elseif (NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5.1)
# Specific flags set(CMAKE_CXX17_STANDARD_COMPILE_OPTION "-std=c++1z")
set(CPP_STD_COMPILER_FLAG "-std=c++14") set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION "-std=gnu++1z")
endif() endif()
endif() endif()
endif()
endif()
else() else()
# C++14 is mandatory # C++14 is mandatory
set(CPP_STD_NUMBER 14) set(CPP_STD_NUMBER 14)
endif() endif()
message(STATUS "SqMod: Using C++${CPP_STD_NUMBER} standard.") message(STATUS "SqMod: Using C++${CPP_STD_NUMBER} standard.")
# Default to the identified standard # Default to the identified standard
if(CMAKE_VERSION VERSION_LESS "3.1") if(CMAKE_VERSION VERSION_LESS "3.1")
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+") if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}") set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}")
endif() endif()
else() else()
# Apparently the above does not work with cmake from on debian 8 # Apparently the above does not work with cmake from on debian 8
if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+") if(${CMAKE_CXX_COMPILER_ID} MATCHES "(GNU)+")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CPP_STD_COMPILER_FLAG}")
endif() endif()
# F* you too Debian. What can I say. # F* you too Debian. What can I say.
if(CMAKE_VERSION VERSION_LESS "3.8.0" AND CPP_STD_NUMBER LESS 17) if(CMAKE_VERSION VERSION_LESS "3.8.0" AND CPP_STD_NUMBER LESS 17)
# Try the standard method as well # Try the standard method as well
set(CMAKE_CXX_STANDARD ${CPP_STD_NUMBER}) set(CMAKE_CXX_STANDARD ${CPP_STD_NUMBER})
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif() endif()
endif() endif()
# Determine if build mode # Determine if build mode
if(${CMAKE_BUILD_TYPE} MATCHES "(Debug)+") if(${CMAKE_BUILD_TYPE} MATCHES "(Debug)+")
add_compile_options(-g) add_compile_options(-g)
endif() endif()
# Enable position independent code # Enable position independent code
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif() endif()
# Include vendor libraries # Include vendor libraries