From 78ee66336a20cfcd14d54c7dee2f1a19cd00d8cb Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Sun, 7 Jan 2024 23:31:31 +0100 Subject: [PATCH] cmake: fix default ninja + add clang-format target (#75) * Add job pools with 1 job to disable parallel builds of lego1 and isle * cmake: add clang-format target --- CMakeLists.txt | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 536c96c6..f0e3eae5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,4 +320,38 @@ if (MSVC) set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "/incremental:no") set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "/incremental:no /debug") set(CMAKE_SHARED_LINKER_FLAGS_MINSIZEREL "/incremental:no") + + # Older MSVC versions don't support building in parallel. + # Force non-parallel builds of isle and lego1 by putting them in a pool with 1 available job. + if(CMAKE_CXX_COMPILER_ID VERSION_LESS 12) + set_property(GLOBAL PROPERTY JOB_POOLS "msvc_lego=1;msvc_lego1=1") + set_property(TARGET isle PROPERTY JOB_POOL_COMPILE msvc_lego) + set_property(TARGET isle PROPERTY JOB_POOL_LINK msvc_lego) + set_property(TARGET lego1 PROPERTY JOB_POOL_COMPILE msvc_lego1) + set_property(TARGET lego1 PROPERTY JOB_POOL_LINK msvc_lego1) + endif() +endif() + +find_program(CLANGFORMAT_BIN NAMES clang-format) +if(EXISTS "${CLANGFORMAT_BIN}") + execute_process(COMMAND "${CLANGFORMAT_BIN}" --version + OUTPUT_VARIABLE "CLANGFORMAT_VERSION_OUTPUT" + RESULT_VARIABLE "CLANGFORMAT_RESULT" + ) + if(CLANGFORMAT_RESULT EQUAL 0 AND CLANGFORMAT_VERSION_OUTPUT MATCHES "version ([0-9\\.]+)") + set(CLANGFORMAT_VERSION "${CMAKE_MATCH_1}") + set(CLANGFORMAT_VERSION_REQUIRED "17.0") + message(DEBUG "Found clang-format version ${CLANGFORMAT_VERSION} (needs ${CLANGFORMAT_VERSION_REQUIRED}") + if(CLANGFORMAT_VERSION VERSION_GREATER_EQUAL "${CLANGFORMAT_VERSION_REQUIRED}") + file(GLOB_RECURSE isle_sources + "${PROJECT_SOURCE_DIR}/ISLE/*.cpp" + "${PROJECT_SOURCE_DIR}/ISLE/*.h" + "${PROJECT_SOURCE_DIR}/LEGO1/*.cpp" + "${PROJECT_SOURCE_DIR}/LEGO1/*.h" + ) + string(REPLACE ";" "\n" isle_sources_lines "${isle_sources}") + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/isle_sources.txt" "${isle_sources_lines}\n") + add_custom_target(clang-format ${CLANGFORMAT_BIN} -i "--files=${CMAKE_CURRENT_BINARY_DIR}/isle_sources.txt") + endif() + endif() endif()