From 6317176d7e890292cb40d6add96a1c81e8eeb08f Mon Sep 17 00:00:00 2001 From: Tiger Wang Date: Thu, 21 May 2020 23:52:19 +0100 Subject: More CMake cleanup --- CMake/AddDependencies.cmake | 81 +++++++++++++++++++++++++++++++++++++++++++++ CMake/StampBuild.cmake | 60 +++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 CMake/AddDependencies.cmake create mode 100644 CMake/StampBuild.cmake (limited to 'CMake') diff --git a/CMake/AddDependencies.cmake b/CMake/AddDependencies.cmake new file mode 100644 index 000000000..72eead340 --- /dev/null +++ b/CMake/AddDependencies.cmake @@ -0,0 +1,81 @@ +# 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.") +set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool.") +set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples.") +set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests.") +set(SQLITECPP_INTERNAL_SQLITE ON CACHE BOOL "Add the internal SQLite3 source to the project.") +set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "Enable Column::getColumnOriginName(). Require support from sqlite3 library.") + +# Set options for LibEvent, disable all their tests and benchmarks: +set(EVENT__DISABLE_OPENSSL YES CACHE BOOL "Disable OpenSSL in LibEvent") +set(EVENT__DISABLE_BENCHMARK YES CACHE BOOL "Disable LibEvent benchmarks") +set(EVENT__DISABLE_TESTS YES CACHE BOOL "Disable LibEvent tests") +set(EVENT__DISABLE_REGRESS YES CACHE BOOL "Disable LibEvent regression tests") +set(EVENT__DISABLE_SAMPLES YES CACHE BOOL "Disable LibEvent samples") +set(EVENT__LIBRARY_TYPE "STATIC" CACHE STRING "Use static LibEvent libraries") + +# Set options for JsonCPP, disabling all of their tests: +set(JSONCPP_WITH_TESTS OFF CACHE BOOL "Compile and (for jsoncpp_check) run JsonCpp test executables") +set(JSONCPP_WITH_POST_BUILD_UNITTEST OFF CACHE BOOL "Automatically run unit-tests as a post build step") +set(JSONCPP_WITH_PKGCONFIG_SUPPORT OFF CACHE BOOL "Generate and install .pc files") + +# Set options for mbedtls: +set(ENABLE_PROGRAMS OFF CACHE BOOL "Build mbed TLS programs.") +set(ENABLE_TESTING OFF CACHE BOOL "Build mbed TLS tests.") + +# Enumerate all submodule libraries +# SQLiteCpp needs to be included before sqlite so the lsqlite target is available: +set(DEPENDENCIES expat fmt jsoncpp libevent lua luaexpat mbedtls SQLiteCpp sqlite tolua++ zlib) +foreach(DEPENDENCY ${DEPENDENCIES}) + # Check that the libraries are present: + if (NOT EXISTS "${PROJECT_SOURCE_DIR}/lib/${DEPENDENCY}/CMakeLists.txt") + message(FATAL_ERROR "${DEPENDENCY} is missing in folder lib/${DEPENDENCY}. Have you initialized and updated the submodules / downloaded the extra libraries?") + endif() + + # Include all the libraries + # We use EXCLUDE_FROM_ALL so that only the explicit dependencies are compiled + # (mbedTLS also has test and example programs in their CMakeLists.txt, we don't want those): + add_subdirectory("lib/${DEPENDENCY}" EXCLUDE_FROM_ALL) +endforeach() + +# Add required includes: +target_include_directories( + ${CMAKE_PROJECT_NAME} SYSTEM PRIVATE + lib/mbedtls/include + lib/TCLAP/include + lib # TODO fix files including zlib/x instead of x +) + +# Link dependencies as private: +target_link_libraries( + ${CMAKE_PROJECT_NAME} PRIVATE + event_core + event_extra + fmt::fmt + jsoncpp_lib + lsqlite + lua + luaexpat + mbedtls + SQLiteCpp + tolualib + zlib +) + +# Link process information library: +if (WIN32) + target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE Psapi.lib) +endif() + +# Special case handling for libevent pthreads: +if(NOT WIN32) + target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE event_pthreads) +endif() + +# Prettify jsoncpp_lib name in VS solution explorer: +set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp") + +if (WIN32) + add_subdirectory(lib/luaproxy) +endif() diff --git a/CMake/StampBuild.cmake b/CMake/StampBuild.cmake new file mode 100644 index 000000000..db234b761 --- /dev/null +++ b/CMake/StampBuild.cmake @@ -0,0 +1,60 @@ +# These env variables are used for configuring Travis CI builds. +if(DEFINED ENV{TRAVIS_CUBERITE_FORCE32}) + set(FORCE32 $ENV{TRAVIS_CUBERITE_FORCE32}) +endif() + +if(DEFINED ENV{TRAVIS_BUILD_WITH_COVERAGE}) + set(BUILD_WITH_COVERAGE $ENV{TRAVIS_BUILD_WITH_COVERAGE}) +endif() + +if(DEFINED ENV{CUBERITE_BUILD_ID}) + # The build info is defined by the build system (Travis / Jenkins) + set(BUILD_ID $ENV{CUBERITE_BUILD_ID}) + set(BUILD_SERIES_NAME $ENV{CUBERITE_BUILD_SERIES_NAME}) + set(BUILD_DATETIME $ENV{CUBERITE_BUILD_DATETIME}) + if(DEFINED ENV{CUBERITE_BUILD_COMMIT_ID}) + set(BUILD_COMMIT_ID $ENV{CUBERITE_BUILD_COMMIT_ID}) + else() + message("Commit id not set, attempting to determine id from git") + execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + RESULT_VARIABLE GIT_EXECUTED + OUTPUT_VARIABLE BUILD_COMMIT_ID + ) + string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) + if (NOT (GIT_EXECUTED EQUAL 0)) + message(FATAL_ERROR "Could not identifiy git commit id") + endif() + endif() +else() + # This is a local build, stuff in some basic info: + set(BUILD_ID "Unknown") + set(BUILD_SERIES_NAME "local build") + execute_process( + COMMAND git rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + RESULT_VARIABLE GIT_EXECUTED + OUTPUT_VARIABLE BUILD_COMMIT_ID + ) + if (NOT(GIT_EXECUTED EQUAL 0)) + set(BUILD_COMMIT_ID "Unknown") + endif() + string(STRIP ${BUILD_COMMIT_ID} BUILD_COMMIT_ID) + execute_process( + COMMAND git log -1 --date=iso --pretty=format:%ai + WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} + RESULT_VARIABLE GIT_EXECUTED + OUTPUT_VARIABLE BUILD_DATETIME + ) + if (NOT(GIT_EXECUTED EQUAL 0)) + set(BUILD_DATETIME "Unknown") + endif() + string(STRIP ${BUILD_DATETIME} BUILD_DATETIME) + + # The BUILD_COMMIT_ID and BUILD_DATETIME aren't updated on each repo pull + # They are only updated when cmake re-configures the project + # Therefore mark them as "approx: " + set(BUILD_COMMIT_ID "approx: ${BUILD_COMMIT_ID}") + set(BUILD_DATETIME "approx: ${BUILD_DATETIME}") +endif() -- cgit v1.2.3