diff --git a/CMakeLists.txt b/CMakeLists.txt index b33c9a9..d74508e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -175,12 +175,8 @@ include(cmake/CPM.cmake) # excluded from the generated target lists for the various tools. set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/third_party_deps) -# ---- Speedup build using ccache ---- -# see https://github.com/TheLartians/Ccache.cmake enables CCACHE support through -# the USE_CCACHE flag possible values are: YES, NO or equivalent -if(USE_CCACHE) - cpmaddpackage("gh:TheLartians/Ccache.cmake@1.2.3") -endif() +# ---- Speedup build using ccache (needs CPM) ---- +include(cmake/FasterBuild.cmake) # ------------------------------------------------------------------------------ # Testing diff --git a/CMakePresets.json b/CMakePresets.json index 38a67d6..73320e2 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -15,10 +15,10 @@ "installDir": "${sourceDir}/out/install/${presetName}", "environment": { "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", - "CPM_SOURCE_CACHE": "$env{HOME}/.cache/CPM", "caexcludepath": "${sourceDir}/third_party;${sourceDir}/out" }, "cacheVariables": { + "CPM_SOURCE_CACHE": "~/.cache/CPM", "USE_CCACHE": "ON", "ASAP_BUILD_TESTS": "ON", "ASAP_BUILD_EXAMPLES": "ON" @@ -432,4 +432,4 @@ "configurePreset": "dev-gcc" } ] -} \ No newline at end of file +} diff --git a/README.md b/README.md index 243c4c9..cc6acf5 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -# Starter project for C++ with modern cmake +# Starter project for C++ with cmake ![Start Now!!](doc/_static/logo.png "ASAP Logo") -[![Build Matrix](https://github.com/abdes/asap/actions/workflows/cmake-build.yml/badge.svg?branch=master)](https://github.com/abdes/asap/actions/workflows/cmake-build.yml) +[![Build Matrix](https://github.com/abdes/asap/actions/workflows/cmake-build.yml/badge.svg?branch=develop)](https://github.com/abdes/asap/actions/workflows/cmake-build.yml) ## [Project Documentation](https://abdes.github.io/asap/asap_master/html/) diff --git a/cmake/AsapTargets.cmake b/cmake/AsapTargets.cmake index ed8040c..92ce110 100644 --- a/cmake/AsapTargets.cmake +++ b/cmake/AsapTargets.cmake @@ -80,8 +80,11 @@ endfunction() function(_module_pkgconfig_files) set(MODULE_PKGCONFIG_FILE ${MODULE_TARGET_NAME}.pc) - get_target_property(TARGET_DEBUG_POSTFIX ${MODULE_TARGET_NAME} DEBUG_POSTFIX) - set(MODULE_LINK_LIBS "-l${MODULE_TARGET_NAME}${TARGET_DEBUG_POSTFIX}") + if(NOT ${type} STREQUAL "INTERFACE_LIBRARY") + get_target_property(TARGET_DEBUG_POSTFIX ${MODULE_TARGET_NAME} + DEBUG_POSTFIX) + set(MODULE_LINK_LIBS "-l${MODULE_TARGET_NAME}${TARGET_DEBUG_POSTFIX}") + endif() configure_file(config.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${MODULE_PKGCONFIG_FILE} @ONLY) if(${META_PROJECT_ID}_INSTALL) @@ -112,16 +115,16 @@ function(asap_add_library target) asap_set_compile_definitions(${target}) # Generate export headers for the library asap_generate_export_headers(${target} ${META_MODULE_NAME}) - endif() - set_target_properties( - ${target} - PROPERTIES FOLDER "Libraries" - VERSION ${META_MODULE_VERSION} - SOVERSION ${META_MODULE_VERSION_MAJOR} - DEBUG_POSTFIX "d" - CXX_VISIBILITY_PRESET hidden - VISIBILITY_INLINES_HIDDEN YES) + set_target_properties( + ${target} + PROPERTIES FOLDER "Libraries" + VERSION ${META_MODULE_VERSION} + SOVERSION ${META_MODULE_VERSION_MAJOR} + DEBUG_POSTFIX "d" + CXX_VISIBILITY_PRESET hidden + VISIBILITY_INLINES_HIDDEN YES) + endif() endfunction() function(asap_add_executable target) diff --git a/cmake/FasterBuild.cmake b/cmake/FasterBuild.cmake new file mode 100644 index 0000000..a0f2536 --- /dev/null +++ b/cmake/FasterBuild.cmake @@ -0,0 +1,22 @@ +# ===-----------------------------------------------------------------------===# +# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or +# copy at https://opensource.org/licenses/BSD-3-Clause). +# SPDX-License-Identifier: BSD-3-Clause +# ===-----------------------------------------------------------------------===# + +# ------------------------------------------------------------------------------ +# Reduce build time by using ccache when available +# ------------------------------------------------------------------------------ + +find_program(CCACHE_TOOL_PATH ccache) + +if(NOT WIN32 AND USE_CCACHE AND CCACHE_TOOL_PATH) + message(STATUS "Using ccache (${CCACHE_TOOL_PATH}) (via wrapper).") + # see https://github.com/TheLartians/Ccache.cmake enables CCACHE support through + # the USE_CCACHE flag possible values are: YES, NO or equivalent + cpmaddpackage("gh:TheLartians/Ccache.cmake@1.2.3") +elseif(WIN32 AND USE_CCACHE AND CCACHE_TOOL_PATH) + set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_TOOL_PATH} CACHE STRING "" FORCE) + message(STATUS "Using ccache (${CCACHE_TOOL_PATH}).") +endif()