1
0
Fork 0

Funktions

This commit is contained in:
Tiger Wang 2020-05-27 23:48:49 +01:00
parent 6317176d7e
commit 2c0fc395ba
6 changed files with 292 additions and 279 deletions

View File

@ -1,3 +1,4 @@
function(build_dependencies TARGET)
# Set options for SQLiteCpp, disable all their tests and lints:
set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "Run cpplint.py tool for Google C++ StyleGuide.")
set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis tool.")
@ -41,7 +42,7 @@ endforeach()
# Add required includes:
target_include_directories(
${CMAKE_PROJECT_NAME} SYSTEM PRIVATE
${TARGET} SYSTEM PRIVATE
lib/mbedtls/include
lib/TCLAP/include
lib # TODO fix files including zlib/x instead of x
@ -49,7 +50,7 @@ target_include_directories(
# Link dependencies as private:
target_link_libraries(
${CMAKE_PROJECT_NAME} PRIVATE
${TARGET} PRIVATE
event_core
event_extra
fmt::fmt
@ -65,12 +66,12 @@ target_link_libraries(
# Link process information library:
if (WIN32)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Psapi.lib)
target_link_libraries(${TARGET} PRIVATE Psapi.lib)
endif()
# Special case handling for libevent pthreads:
if(NOT WIN32)
target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE event_pthreads)
target_link_libraries(${TARGET} PRIVATE event_pthreads)
endif()
# Prettify jsoncpp_lib name in VS solution explorer:
@ -79,3 +80,4 @@ set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp")
if (WIN32)
add_subdirectory(lib/luaproxy)
endif()
endfunction()

View File

@ -1,3 +1,4 @@
function(emit_fixups)
# TODO these should be in the submodules
# Under Windows, we need Lua as DLL; on *nix we need it linked statically:
if (WIN32)
@ -12,3 +13,4 @@ if(NOT MSVC AND "${CMAKE_SYSTEM_PROCESSOR}" MATCHES "arm")
# https://tls.mbed.org/kb/development/arm-thumb-error-r7-cannot-be-used-in-asm-here
target_compile_options(mbedcrypto PRIVATE -fomit-frame-pointer)
endif()
endfunction()

View File

@ -1,3 +1,4 @@
function(enable_bindings_generation)
# Enumerate every Lua-exported class.
# Changes to these files will cause binding regen:
set(BINDING_DEPENDENCIES
@ -110,3 +111,4 @@ add_custom_command(
WORKING_DIRECTORY ${BINDINGS_FOLDER}
DEPENDS ${BINDING_DEPENDENCIES} luaexe
)
endfunction()

View File

@ -1,3 +1,4 @@
function(group_sources)
# Enable the support for solution folders in MSVC
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
@ -40,3 +41,4 @@ endif()
# Put all files into one project, separate by the folders:
get_property(TARGET_SOURCE_FILES TARGET ${CMAKE_PROJECT_NAME} PROPERTY SOURCES)
source_group(TREE "${PROJECT_SOURCE_DIR}/src" FILES ${TARGET_SOURCE_FILES})
endfunction()

View File

@ -28,7 +28,19 @@ option(PRECOMPILE_HEADERS "Enable precompiled headers for faster builds" ON)
option(SELF_TEST "Enables testing code to be built" OFF)
option(UNITY_BUILDS "Enables source aggregation for faster builds" ON)
# We need C++17 features
include("CMake/AddDependencies.cmake")
include("CMake/Fixups.cmake")
include("CMake/GenerateBindings.cmake")
include("CMake/GroupSources.cmake")
include("SetFlags.cmake")
# Add build timestamp and details:
include("CMake/StampBuild.cmake")
# TODO: set_build_stamp()
set_global_flags()
# We need C++17 features:
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
@ -40,15 +52,15 @@ if(WHOLE_PROGRAM_OPTIMISATION)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${IPO_SUPPORTED})
endif()
# Static CRT
# Static CRT:
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
# Add build timestamp and details:
include("CMake/StampBuild.cmake")
add_executable(${CMAKE_PROJECT_NAME})
add_subdirectory(src)
enable_warnings(${CMAKE_PROJECT_NAME})
build_dependencies(${CMAKE_PROJECT_NAME})
# Set the startup project to Cuberite, and the debugger dir:
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME})
set_target_properties(${CMAKE_PROJECT_NAME} PROPERTIES VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/Server")
@ -93,8 +105,6 @@ if(${SELF_TEST})
add_subdirectory(tests)
endif()
include("CMake/AddDependencies.cmake")
include("CMake/Fixups.cmake")
include("CMake/GenerateBindings.cmake")
include("CMake/GroupSources.cmake")
include("SetFlags.cmake")
emit_fixups()
group_sources()
enable_bindings_generation()

View File

@ -81,19 +81,16 @@ macro(enable_profile)
endif()
endmacro()
# Add coverage processing, if requested:
if (NOT MSVC)
if (CMAKE_BUILD_TYPE STREQUAL "COVERAGE")
message("Including CodeCoverage")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/lib/cmake-coverage/")
include(CodeCoverage)
endif()
endif()
function(set_global_flags)
if(MSVC)
# Make build use multiple threads under MSVC:
add_compile_options(/MP)
# Make build use Unicode:
add_compile_definitions(UNICODE _UNICODE)
else()
# TODO: is this needed? NDEBUG is standard. Also, why are we using _DEBUG?
# Add the preprocessor macros used for distinguishing between debug and release builds (CMake does this automatically for MSVC):
if (NOT MSVC)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -D_DEBUG")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -D_DEBUG")
@ -102,17 +99,26 @@ if (NOT MSVC)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -DNDEBUG")
endif()
# Allow for a forced 32-bit build under 64-bit OS:
if (FORCE_32)
add_compile_options(-m32)
add_link_options(-m32)
endif()
# Have the compiler generate code specifically targeted at the current machine on Linux:
if(LINUX AND NOT NO_NATIVE_OPTIMIZATION)
add_compile_options(-march=native)
endif()
endfunction()
function(enable_warnings TARGET)
if (MSVC)
# Make build use multiple threads under MSVC:
add_compile_options(/MP)
# TODO: MSVC level 4, warnings as errors
return ()
endif()
# Make build use Unicode:
add_compile_definitions(UNICODE _UNICODE)
# TODO: level 4, warnings as errors
else()
target_compile_options(
${CMAKE_PROJECT_NAME} PRIVATE
${TARGET} PRIVATE
# We use a signed char (fixes #640 on RasPi)
# TODO: specify this in code, not a compile flag:
@ -135,7 +141,7 @@ else()
if(CMAKE_CXX_COMPILE_ID STREQUAL "Clang")
target_compile_options(
${CMAKE_PROJECT_NAME}Cuberite PRIVATE
${TARGET} PRIVATE
# Warnings-as-errors only on Clang for now:
-Werror
@ -147,15 +153,4 @@ else()
-Wno-error=unused-command-line-argument
)
endif()
endif()
# Allow for a forced 32-bit build under 64-bit OS:
if (FORCE_32)
add_flags_cxx("-m32")
add_flags_lnk("-m32")
endif()
# Have the compiler generate code specifically targeted at the current machine on Linux:
if(LINUX AND NOT NO_NATIVE_OPTIMIZATION)
add_flags_cxx("-march=native")
endif()
endfunction()