diff options
author | Sven Göthel <[email protected]> | 2024-08-08 23:42:38 +0200 |
---|---|---|
committer | Sven Göthel <[email protected]> | 2024-08-08 23:42:38 +0200 |
commit | 1066c9942422235fd40a7d7f9583c400892d0162 (patch) | |
tree | 47a169616bbf95632669d102eae5f14fb9853203 | |
parent | fbdd386ceaf4d3adb5b19a691cb6991d54d8d96b (diff) |
cmake preset: Use '--parallel' for auto cpu-count selection (also for vscode); Use plain 'build/<preset>' name and 'dist/<preset>-tripple' or 'dist/<preset>-tripple-<toolset>'
-rw-r--r-- | .vscode/settings.json | 9 | ||||
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | CMakePresets.json | 28 | ||||
-rw-r--r-- | JaulibSetup.cmake | 6 | ||||
-rw-r--r-- | README.md | 24 | ||||
-rwxr-xr-x | scripts/build-preset-target.sh | 74 | ||||
-rwxr-xr-x | scripts/build-preset.sh | 23 | ||||
-rwxr-xr-x | scripts/rebuild-preset-doc.sh | 12 | ||||
-rwxr-xr-x | scripts/rebuild-preset.sh | 12 |
9 files changed, 138 insertions, 55 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json index 80f33b5..54d54b9 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,11 +4,18 @@ "*.cpp": "cpp", "*.cxx": "cpp" }, + "cmake.useCMakePresets": "always", "cmake.configureOnOpen": true, "cmake.copyCompileCommands": "${workspaceFolder}/compile_commands.json", "cmake.sourceDirectory": "${workspaceFolder}", "cmake.configureArgs": [ - "-DJAU_CMAKE_ENFORCE_PRESETS=ON" + ], + // "cmake.parallelJobs": 16, + "cmake.buildEnvironment": { + // "CMAKE_BUILD_PARALLEL_LEVEL": "16" + }, + "cmake.buildArgs": [ + "--parallel", ], "clangd.arguments": [ "--background-index", diff --git a/CMakeLists.txt b/CMakeLists.txt index f295e2b..c4ffd5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,13 +34,12 @@ endif() JaulibSetup() -if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.clangd) # Fixup clangd w/ absolute path set (jaulib_clangd_source_args "-isystem, ${CMAKE_CURRENT_SOURCE_DIR}/include, -isystem, ${CMAKE_CURRENT_SOURCE_DIR}/src, -isystem, ${CMAKE_CURRENT_SOURCE_DIR}/java_jni/jni, -isystem, ${CMAKE_CURRENT_SOURCE_DIR}/java_jni/jni/jau") set (jaulib_clangd_source_args "${jaulib_clangd_source_args}, -isystem, ${CMAKE_CURRENT_SOURCE_DIR}/include/catch2_jau, -isystem, ${CMAKE_CURRENT_SOURCE_DIR}/test") configure_file (${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/clangd.in - ${CMAKE_CURRENT_SOURCE_DIR}/.clangd) -endif() + ${CMAKE_CURRENT_BINARY_DIR}/.clangd) +file(COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/.clangd ${CMAKE_CURRENT_SOURCE_DIR}/.clangd) # this is the library version, derived from git tag and revision set (jaulib_VERSION_MAJOR ${VERSION_MAJOR}) diff --git a/CMakePresets.json b/CMakePresets.json index e88a812..83a3bdc 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -9,11 +9,11 @@ { "name": "debug", "displayName": "Debug (cc, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-debug", + "binaryDir": "${sourceDir}/build/debug", "cacheVariables": { "CMAKE_CXX_STANDARD": "20", "CMAKE_BUILD_TYPE": "Debug", - "CMAKE_INSTALL_PREFIX": "dist/preset-debug", + "CMAKE_INSTALL_PREFIX": "dist/debug", "JAU_CMAKE_FIX_INSTALL_PREFIX": "ON", "TRY_ALL": "ON", "TRY_JAVA": "ON", @@ -27,21 +27,21 @@ "name": "debug-clang", "inherits": "debug", "displayName": "Debug (clang, clang-tidy, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-debug-clang", + "binaryDir": "${sourceDir}/build/debug-clang", "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "dist/preset-debug-clang", + "CMAKE_INSTALL_PREFIX": "dist/debug-clang", "CMAKE_C_COMPILER": "clang", "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_CXX_CLANG_TIDY": "clang-tidy;-p;${sourceDir}/build/preset-debug-clang" + "CMAKE_CXX_CLANG_TIDY": "clang-tidy;-p;${sourceDir}/build/debug-clang" } }, { "name": "debug-gcc", "inherits": "debug", "displayName": "Debug (gcc, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-debug-gcc", + "binaryDir": "${sourceDir}/build/debug-gcc", "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "dist/preset-debug-gcc", + "CMAKE_INSTALL_PREFIX": "dist/debug-gcc", "CMAKE_C_COMPILER": "gcc", "CMAKE_CXX_COMPILER": "g++" } @@ -50,10 +50,10 @@ "name": "release", "inherits": "debug", "displayName": "Release (cc, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-release", + "binaryDir": "${sourceDir}/build/release", "cacheVariables": { "CMAKE_BUILD_TYPE": "Release", - "CMAKE_INSTALL_PREFIX": "dist/preset-release", + "CMAKE_INSTALL_PREFIX": "dist/release", "JAU_CMAKE_FIX_INSTALL_PREFIX": "ON", "TEST_WITH_SUDO": "ON" } @@ -62,21 +62,21 @@ "name": "release-clang", "inherits": "release", "displayName": "Release (clang, clang-tidy, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-release-clang", + "binaryDir": "${sourceDir}/build/release-clang", "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "dist/preset-release-clang", + "CMAKE_INSTALL_PREFIX": "dist/release-clang", "CMAKE_C_COMPILER": "clang", "CMAKE_CXX_COMPILER": "clang++", - "CMAKE_CXX_CLANG_TIDY": "clang-tidy;-p;${sourceDir}/build/preset-release-clang" + "CMAKE_CXX_CLANG_TIDY": "clang-tidy;-p;${sourceDir}/build/release-clang" } }, { "name": "release-gcc", "inherits": "release", "displayName": "Release (gcc, C++20, java)", - "binaryDir": "${sourceDir}/build/preset-release-gcc", + "binaryDir": "${sourceDir}/build/release-gcc", "cacheVariables": { - "CMAKE_INSTALL_PREFIX": "dist/preset-release-gcc", + "CMAKE_INSTALL_PREFIX": "dist/release-gcc", "CMAKE_C_COMPILER": "gcc", "CMAKE_CXX_COMPILER": "g++" } diff --git a/JaulibSetup.cmake b/JaulibSetup.cmake index cbc3b9b..6040797 100644 --- a/JaulibSetup.cmake +++ b/JaulibSetup.cmake @@ -189,7 +189,11 @@ if( (JAU_CMAKE_OVERRIDE_INSTALL_PREFIX) OR (NOT DEFINED CMAKE_INSTALL_PREFIX) ) endif() if(JAU_CMAKE_FIX_INSTALL_PREFIX) set(JAU_CMAKE_FIX_INSTALL_PREFIX OFF) - set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}-${OS_AND_ARCH}-${TOOLSET}") + if(CMAKE_INSTALL_PREFIX MATCHES "-${TOOLSET}$") + set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}-${OS_AND_ARCH}") + else() + set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}-${OS_AND_ARCH}-${TOOLSET}") + endif() set(CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE PATH "" FORCE) message(STATUS "JaulibSetup: Setting(2) CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}") endif() @@ -239,37 +239,37 @@ Following debug presets are defined in `CMakePresets.json` - libcurl (if available) - testing on - testing with sudo off - - binary-dir `build/preset-debug` - - install-dir `dist/preset-debug` + - binary-dir `build/debug` + - install-dir `dist/debug` - `debug-clang` - inherits from `debug` - compiler: `clang` - enabled `clang-tidy` - - binary-dir `build/preset-debug-clang` - - install-dir `dist/preset-debug-clang` + - binary-dir `build/debug-clang` + - install-dir `dist/debug-clang` - `debug-gcc` - inherits from `debug` - compiler: `gcc` - disabled `clang-tidy` - - binary-dir `build/preset-debug-gcc` - - install-dir `dist/preset-debug-gcc` + - binary-dir `build/debug-gcc` + - install-dir `dist/debug-gcc` - `release` - inherits from `debug` - debug disabled - disabled `clang-tidy` - testing with sudo on - - binary-dir `build/preset-release` - - install-dir `dist/preset-release` + - binary-dir `build/release` + - install-dir `dist/release` - `release-clang` - compiler: `clang` - enabled `clang-tidy` - - binary-dir `build/preset-release-gcc` - - install-dir `dist/preset-release-gcc` + - binary-dir `build/release-clang` + - install-dir `dist/release-clang` - `release-gcc` - compiler: `gcc` - disabled `clang-tidy` - - binary-dir `build/preset-release-gcc` - - install-dir `dist/preset-release-gcc` + - binary-dir `build/release-gcc` + - install-dir `dist/release-gcc` - **`default`** - inherits from `debug-clang` - binary-dir `build/default` diff --git a/scripts/build-preset-target.sh b/scripts/build-preset-target.sh new file mode 100755 index 0000000..313dc1c --- /dev/null +++ b/scripts/build-preset-target.sh @@ -0,0 +1,74 @@ +#! /bin/sh + +sdir=`dirname $(readlink -f $0)` +rootdir=`dirname $sdir` +bname=`basename $0 .sh` + +. $sdir/setup-machine-arch.sh + +tripleid="$os_name-$archabi" + +if [ ! -z "$1" ] ; then + preset_name=$1 + shift 1 +else + echo "ERROR: No preset passed as 1st argument, use one of:" + cmake --list-presets + return 1 +fi + +if [ ! -z "$1" ] ; then + target_name=$1 + shift 1 +else + echo "ERROR: No target passed as 2nd argument, use one of: [clean, all, install, doc_jau, test]" + return 1 +fi + +logfile=$rootdir/${bname}-${preset_name}-${target_name}-${tripleid}.log +rm -f $logfile + +CPU_COUNT=`getconf _NPROCESSORS_ONLN` + +# run as root 'dpkg-reconfigure locales' enable 'en_US.UTF-8' +# perhaps run as root 'update-locale LC_MEASUREMENT=en_US.UTF-8 LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8' +export LC_MEASUREMENT=en_US.UTF-8 +export LC_ALL=en_US.UTF-8 +export LANG=en_US.UTF-8 + +buildit() { + if [ -z "$JAVA_HOME" -o ! -e "$JAVA_HOME" ] ; then + echo "WARNING: JAVA_HOME $JAVA_HOME does not exist" + else + echo JAVA_HOME $JAVA_HOME + fi + echo rootdir $rootdir + echo logfile $logfile + echo CPU_COUNT $CPU_COUNT + + dist_dir="dist/${preset_name}-${tripleid}" + build_dir="build/${preset_name}" + echo dist_dir $dist_dir + echo build_dir $build_dir + + if [ -x /usr/bin/time ] ; then + time_cmd="time" + echo "time command available: ${time_cmd}" + else + time_cmd="" + echo "time command not available" + fi + + cd $rootdir + + ${time_cmd} cmake --build --preset ${preset_name} --target ${target_name} --parallel + if [ $? -eq 0 ] ; then + echo "REBUILD SUCCESS $bname, preset $preset_name, target $target_name, $tripleid" + return 0 + else + echo "REBUILD FAILURE $bname, preset $preset_name, target $target_name, $tripleid" + return 1 + fi +} + +buildit 2>&1 | tee $logfile diff --git a/scripts/build-preset.sh b/scripts/build-preset.sh index c2f3fd7..b9a44d9 100755 --- a/scripts/build-preset.sh +++ b/scripts/build-preset.sh @@ -6,7 +6,7 @@ bname=`basename $0 .sh` . $sdir/setup-machine-arch.sh -tripleid="$os_name-$archabi-gcc" +tripleid="$os_name-$archabi" if [ ! -z "$1" ] ; then preset_name=$1 @@ -38,8 +38,8 @@ buildit() { echo logfile $logfile echo CPU_COUNT $CPU_COUNT - dist_dir="dist/preset-${preset_name}" - build_dir="build/preset-${preset_name}" + dist_dir="dist/${preset_name}-${tripleid}" + build_dir="build/${preset_name}" echo dist_dir $dist_dir echo build_dir $build_dir @@ -52,28 +52,27 @@ buildit() { fi cd $rootdir - rm -rf $dist_dir - mkdir -p $dist_dir + rm -rf $dist_dir dist/${preset_name} rm -rf $build_dir mkdir -p $build_dir cmake --preset ${preset_name} - # ${time_cmd} cmake --build --preset ${preset_name} --parallel $CPU_COUNT --target test install doc_jau - # ${time_cmd} cmake --build --preset ${preset_name} --parallel $CPU_COUNT - ${time_cmd} cmake --build --preset ${preset_name} --parallel $CPU_COUNT --target install + # ${time_cmd} cmake --build --preset ${preset_name} --target test install doc_jau --parallel + # ${time_cmd} cmake --build --preset ${preset_name} --parallel + ${time_cmd} cmake --build --preset ${preset_name} --target install --parallel if [ $? -eq 0 ] ; then - echo "BUILD SUCCESS $bname $tripleid" + echo "BUILD SUCCESS $bname, preset $preset_name, $tripleid" ${time_cmd} cmake --build --preset ${preset_name} --target test if [ $? -eq 0 ] ; then - echo "TEST SUCCESS $bname $tripleid" + echo "TEST SUCCESS $bname, preset $preset_name, $tripleid" return 0 else - echo "TEST FAILURE $bname $tripleid" + echo "TEST FAILURE $bname, preset $preset_name, $tripleid" return 1 fi else - echo "BUILD FAILURE $bname $tripleid" + echo "BUILD FAILURE $bname, preset $preset_name, $tripleid" return 1 fi } diff --git a/scripts/rebuild-preset-doc.sh b/scripts/rebuild-preset-doc.sh index 734b109..d315ce7 100755 --- a/scripts/rebuild-preset-doc.sh +++ b/scripts/rebuild-preset-doc.sh @@ -6,7 +6,7 @@ bname=`basename $0 .sh` . $sdir/setup-machine-arch.sh -tripleid="$os_name-$archabi-gcc" +tripleid="$os_name-$archabi" if [ ! -z "$1" ] ; then preset_name=$1 @@ -38,8 +38,8 @@ buildit() { echo logfile $logfile echo CPU_COUNT $CPU_COUNT - dist_dir="dist/preset-${preset_name}" - build_dir="build/preset-${preset_name}" + dist_dir="dist/${preset_name}-${tripleid}" + build_dir="build/${preset_name}" echo dist_dir $dist_dir echo build_dir $build_dir @@ -53,16 +53,16 @@ buildit() { cd $rootdir - ${time_cmd} cmake --build --preset ${preset_name} --parallel $CPU_COUNT --target doc_jau + ${time_cmd} cmake --build --preset ${preset_name} --target doc_jau --parallel if [ $? -eq 0 ] ; then - echo "REBUILD SUCCESS $bname $tripleid" + echo "REBUILD SUCCESS $bname, preset $preset_name, $tripleid" cd ${build_dir} rm -f $rootdir/documentation.tar.xz tar caf $rootdir/documentation.tar.xz documentation cd $rootdir return 0 else - echo "REBUILD FAILURE $bname $tripleid" + echo "REBUILD FAILURE $bname, preset $preset_name, $tripleid" return 1 fi } diff --git a/scripts/rebuild-preset.sh b/scripts/rebuild-preset.sh index ebc3e27..42ad901 100755 --- a/scripts/rebuild-preset.sh +++ b/scripts/rebuild-preset.sh @@ -6,7 +6,7 @@ bname=`basename $0 .sh` . $sdir/setup-machine-arch.sh -tripleid="$os_name-$archabi-gcc" +tripleid="$os_name-$archabi" if [ ! -z "$1" ] ; then preset_name=$1 @@ -38,8 +38,8 @@ buildit() { echo logfile $logfile echo CPU_COUNT $CPU_COUNT - dist_dir="dist/preset-${preset_name}" - build_dir="build/preset-${preset_name}" + dist_dir="dist/${preset_name}-${tripleid}" + build_dir="build/preset_name}" echo dist_dir $dist_dir echo build_dir $build_dir @@ -53,12 +53,12 @@ buildit() { cd $rootdir - ${time_cmd} cmake --build --preset ${preset_name} --parallel $CPU_COUNT --target install + ${time_cmd} cmake --build --preset ${preset_name} --target install --parallel if [ $? -eq 0 ] ; then - echo "REBUILD SUCCESS $bname $tripleid" + echo "REBUILD SUCCESS $bname, preset $preset_name, $tripleid" return 0 else - echo "REBUILD FAILURE $bname $tripleid" + echo "REBUILD FAILURE $bname, preset $preset_name, $tripleid" return 1 fi } |