1
0
Fork 0

Fix march=native not being enabled

* LINUX doesn't exist apparently, use UNIX instead
+ Add some platform-specific logic to determine whether to use mcpu or march
- Remove duplicated compile option comments
+ Add STATUS level to messages
This commit is contained in:
Tiger Wang 2021-01-31 15:09:59 +00:00
parent 2a6d4ffcd8
commit 2f1359a0f9
3 changed files with 22 additions and 25 deletions

View File

@ -1,20 +1,6 @@
# This is the top-level CMakeLists.txt file for the Cuberite project # This is the top-level CMakeLists.txt file for the Cuberite project
# #
# Use CMake to generate the build files for your platform # Use CMake to generate the build files for your platform
#
# This script supports some configuration through CMake arguments (-Dparam=val syntax):
# BUILD_TOOLS=1 sets up additional executables to be built along with the server (ProtoProxy, GrownBiomeGenVisualiser, MCADefrag)
# BUILD_UNSTABLE_TOOLS=1 sets up yet more executables to be built, these can be broken and generally are obsolete (GeneratorPerformanceTest)
# NO_NATIVE_OPTIMIZATION=1 disables CPU-specific optimisations for the current machine, allows use on other CPUs of the same platform
# DISABLE_SYSTEM_LUA=1 disables the use of system Lua interpreter; the tolua executable will be built and used instead. Incompatible with cross-compiling
# SELF_TEST=1 enables testing code to be built
# UNITY_BUILDS=OFF disables unity builds
# PRECOMPILE_HEADERS=OFF disables precompiled headers
# WHOLE_PROGRAM_OPTIMISATION=OFF disables link time optimisation
cmake_minimum_required (VERSION 3.13) cmake_minimum_required (VERSION 3.13)
cmake_policy(VERSION 3.13...3.17.2) cmake_policy(VERSION 3.13...3.17.2)
@ -26,10 +12,12 @@ project(
) )
option(BUILD_TOOLS "Sets up additional executables to be built along with the server" OFF) option(BUILD_TOOLS "Sets up additional executables to be built along with the server" OFF)
option(WHOLE_PROGRAM_OPTIMISATION "Enables link time optimisation for Release" ON) option(BUILD_UNSTABLE_TOOLS "Sets up yet more executables to be built, these can be broken and generally are obsolete" OFF)
option(NO_NATIVE_OPTIMIZATION "Disables CPU-specific optimisations for the current machine, allows use on other CPUs of the same platform" OFF)
option(PRECOMPILE_HEADERS "Enable precompiled headers for faster builds" ON) option(PRECOMPILE_HEADERS "Enable precompiled headers for faster builds" ON)
option(SELF_TEST "Enables testing code to be built" OFF) option(SELF_TEST "Enables testing code to be built" OFF)
option(UNITY_BUILDS "Enables source aggregation for faster builds" ON) option(UNITY_BUILDS "Enables source aggregation for faster builds" ON)
option(WHOLE_PROGRAM_OPTIMISATION "Enables link time optimisation for Release" ON)
include("CMake/AddDependencies.cmake") include("CMake/AddDependencies.cmake")
include("CMake/Fixups.cmake") include("CMake/Fixups.cmake")
@ -91,22 +79,22 @@ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set_source_files_properties("${PROJECT_SOURCE_DIR}/src/Bindings/Bindings.cpp" PROPERTIES COMPILE_OPTIONS -w) set_source_files_properties("${PROJECT_SOURCE_DIR}/src/Bindings/Bindings.cpp" PROPERTIES COMPILE_OPTIONS -w)
endif() endif()
if(${BUILD_TOOLS}) if(BUILD_TOOLS)
message("Building tools") message(STATUS "Building tools")
add_subdirectory(Tools/GrownBiomeGenVisualiser/) add_subdirectory(Tools/GrownBiomeGenVisualiser/)
add_subdirectory(Tools/MCADefrag/) add_subdirectory(Tools/MCADefrag/)
add_subdirectory(Tools/NoiseSpeedTest/) add_subdirectory(Tools/NoiseSpeedTest/)
add_subdirectory(Tools/ProtoProxy/) add_subdirectory(Tools/ProtoProxy/)
endif() endif()
if(${BUILD_UNSTABLE_TOOLS}) if(BUILD_UNSTABLE_TOOLS)
message("Building unstable tools") message(STATUS "Building unstable tools")
add_subdirectory(Tools/GeneratorPerformanceTest/) add_subdirectory(Tools/GeneratorPerformanceTest/)
endif() endif()
# Self Test Mode enables extra checks at startup # Self Test Mode enables extra checks at startup
if(${SELF_TEST}) if(SELF_TEST)
message("Tests enabled") message(STATUS "Tests enabled")
enable_testing() enable_testing()
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()

View File

@ -96,9 +96,18 @@ function(set_global_flags)
add_link_options(-m32) add_link_options(-m32)
endif() endif()
# https://en.wikipedia.org/wiki/Uname
# https://gcc.gnu.org/onlinedocs/gcc/index.html
# Have the compiler generate code specifically targeted at the current machine on Linux: # Have the compiler generate code specifically targeted at the current machine on Linux:
if(LINUX AND NOT NO_NATIVE_OPTIMIZATION) if(UNIX AND NOT NO_NATIVE_OPTIMIZATION AND NOT CMAKE_CROSSCOMPILING)
add_compile_options(-march=native) string(TOLOWER ${CMAKE_SYSTEM_PROCESSOR} SYSTEM_PROCESSOR)
if (SYSTEM_PROCESSOR MATCHES "^(i386|i686|x86|amd64|mips)")
message(STATUS "Optimising for this machine (march=native)")
add_compile_options(-march=native)
elseif (SYSTEM_PROCESSOR MATCHES "^(arm|aarch|powerpc|ppc|sparc|alpha)")
message(STATUS "Optimising for this machine (mcpu=native)")
add_compile_options(-mcpu=native)
endif()
endif() endif()
endfunction() endfunction()

View File

@ -210,7 +210,7 @@ function(make_symlink orig link)
endif() endif()
# Create the symlink (platform-dependent): # Create the symlink (platform-dependent):
message("Creating symlink, orig = ${orig}; link = ${link}") message(STATUS "Creating symlink, orig = ${orig}; link = ${link}")
if (CMAKE_HOST_UNIX) if (CMAKE_HOST_UNIX)
set(command ln -s ${orig} ${link}) set(command ln -s ${orig} ${link})
else() else()
@ -254,7 +254,7 @@ set(symlinks
monsters.ini monsters.ini
README.txt README.txt
) )
message("Creating output folder and symlinks...") message(STATUS "Creating output folder and symlinks...")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Server") file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/Server")
foreach (symlink ${symlinks}) foreach (symlink ${symlinks})
make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/../Server/${symlink}" "${CMAKE_BINARY_DIR}/Server/${symlink}") make_symlink("${CMAKE_CURRENT_SOURCE_DIR}/../Server/${symlink}" "${CMAKE_BINARY_DIR}/Server/${symlink}")