2021-11-11 21:22:24 +01:00
|
|
|
# Set compilers settings for all platforms/compilers.
|
2024-03-17 12:47:11 +01:00
|
|
|
# ---------------------------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# -----------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Includes modules
|
|
|
|
include(CheckIncludeFiles)
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Enables IDE folders y default
|
|
|
|
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Available build options
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Lists all the cxx flags
|
|
|
|
set(cxx_all_flags
|
|
|
|
CMAKE_CXX_FLAGS
|
|
|
|
CMAKE_C_FLAGS
|
|
|
|
CMAKE_CXX_FLAGS_DEBUG
|
|
|
|
CMAKE_C_FLAGS_DEBUG
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL
|
|
|
|
CMAKE_C_FLAGS_MINSIZEREL
|
|
|
|
CMAKE_CXX_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_C_FLAGS_RELWITHDEBINFO
|
|
|
|
CMAKE_CXX_FLAGS_RELEASE
|
|
|
|
CMAKE_C_FLAGS_RELEASE)
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# --------------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Cross compiler compilation flags
|
|
|
|
|
|
|
|
# Requires C++11
|
2023-03-26 11:44:29 +02:00
|
|
|
if(NOT CMAKE_CXX_STANDARD)
|
|
|
|
set(CMAKE_CXX_STANDARD 11)
|
|
|
|
endif()
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
|
|
|
|
# Simd math force ref
|
|
|
|
if(ozz_build_simd_ref)
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_definitions(OZZ_BUILD_SIMD_REF)
|
2021-11-11 21:22:24 +01:00
|
|
|
endif()
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# --------------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Modify default MSVC compilation flags
|
2023-03-26 11:44:29 +02:00
|
|
|
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
|
2024-03-17 12:47:11 +01:00
|
|
|
# ---------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# For the common build flags
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# Disables crt secure warnings
|
|
|
|
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
|
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
# Adds support for multiple processes builds
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(/MP)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
|
|
|
# Set the warning level to W4
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(/W4)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
|
|
|
# Set warning as error
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(/WX)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
|
|
|
# Select whether to use the DLL version or the static library version of the Visual C++ runtime library.
|
2024-03-17 12:47:11 +01:00
|
|
|
if(ozz_build_msvc_rt_dll)
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
|
|
|
else()
|
|
|
|
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# --------------------------------------
|
2023-03-26 11:44:29 +02:00
|
|
|
# else consider the compiler as GCC compatible (inc clang)
|
2021-11-11 21:22:24 +01:00
|
|
|
else()
|
|
|
|
# Set the warning level to Wall
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(-Wall)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
|
|
|
# Enable extra level of warning
|
2024-03-17 12:47:11 +01:00
|
|
|
# add_compile_options(-Wextra)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
|
|
|
# Set warning as error
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(-Werror)
|
2021-11-11 21:22:24 +01:00
|
|
|
|
2023-03-26 11:44:29 +02:00
|
|
|
# ignored-attributes reports issue when using _m128 as template argument
|
2021-11-11 21:22:24 +01:00
|
|
|
check_cxx_compiler_flag("-Wignored-attributes" W_IGNORED_ATTRIBUTES)
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
if(W_IGNORED_ATTRIBUTES)
|
2023-03-26 11:44:29 +02:00
|
|
|
add_compile_options(-Wno-ignored-attributes)
|
2021-11-11 21:22:24 +01:00
|
|
|
endif()
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2023-03-26 11:44:29 +02:00
|
|
|
# Disables c98 retrocompatibility warnings
|
|
|
|
check_cxx_compiler_flag("-Wc++98-compat-pedantic" W_98_COMPAT_PEDANTIC)
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2023-03-26 11:44:29 +02:00
|
|
|
if(W_98_COMPAT_PEDANTIC)
|
|
|
|
add_compile_options(-Wno-c++98-compat-pedantic)
|
2021-11-11 21:22:24 +01:00
|
|
|
endif()
|
|
|
|
|
2023-03-26 11:44:29 +02:00
|
|
|
# Check some options availibity for the targetted compiler
|
2024-03-17 12:47:11 +01:00
|
|
|
check_cxx_compiler_flag("-Wunused-result" W_UNUSED_RESULT)
|
2021-11-11 21:22:24 +01:00
|
|
|
check_cxx_compiler_flag("-Wnull-dereference" W_NULL_DEREFERENCE)
|
|
|
|
check_cxx_compiler_flag("-Wpragma-pack" W_PRAGMA_PACK)
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ----------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Sets emscripten output
|
|
|
|
if(EMSCRIPTEN)
|
|
|
|
SET(CMAKE_EXECUTABLE_SUFFIX ".html")
|
|
|
|
add_link_options(-s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=0)
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# if(NOT ozz_build_simd_ref)
|
|
|
|
# set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS "-msse2")
|
|
|
|
# endif()
|
2021-11-11 21:22:24 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ---------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Prints all the flags
|
|
|
|
message(STATUS "---------------------------------------------------------")
|
|
|
|
message(STATUS "Default build type is: ${CMAKE_BUILD_TYPE}")
|
|
|
|
message(STATUS "The following compilation flags will be used:")
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
foreach(flag ${cxx_all_flags})
|
|
|
|
message(${flag} " ${${flag}}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
message(STATUS "---------------------------------------------------------")
|
|
|
|
|
|
|
|
get_directory_property(DirectoryCompileOptions DIRECTORY ${PROJECT_SOURCE_DIR} COMPILE_OPTIONS)
|
|
|
|
message(STATUS "Directory Compile Options:")
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
foreach(opt ${DirectoryCompileOptions})
|
|
|
|
message(STATUS ${opt})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
message(STATUS "---------------------------------------------------------")
|
|
|
|
|
|
|
|
get_directory_property(DirectoryCompileDefinitions DIRECTORY ${PROJECT_SOURCE_DIR} COMPILE_DEFINITIONS)
|
|
|
|
message(STATUS "Directory Compile Definitions:")
|
2024-03-17 12:47:11 +01:00
|
|
|
|
2021-11-11 21:22:24 +01:00
|
|
|
foreach(def ${DirectoryCompileDefinitions})
|
|
|
|
message(STATUS ${def})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
message(STATUS "---------------------------------------------------------")
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# ----------------------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Modifies output directory for all executables
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ".")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ".")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ".")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_MINSIZEREL ".")
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ".")
|
|
|
|
|
2024-03-17 12:47:11 +01:00
|
|
|
# -------------------------------
|
2021-11-11 21:22:24 +01:00
|
|
|
# Set a postfix for output files
|
|
|
|
if(ozz_build_postfix)
|
|
|
|
set(CMAKE_DEBUG_POSTFIX "_d")
|
|
|
|
set(CMAKE_RELEASE_POSTFIX "_r")
|
|
|
|
set(CMAKE_MINSIZEREL_POSTFIX "_rs")
|
|
|
|
set(CMAKE_RELWITHDEBINFO_POSTFIX "_rd")
|
2023-03-26 11:44:29 +02:00
|
|
|
endif()
|