From 2c8ad10f2b3fcb754bbdd5dc621c4eec1e3d47f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Chr=C3=A9tien?= Date: Tue, 24 Nov 2015 00:26:32 +0900 Subject: [PATCH] Improve CMake module - Add support for CMake generators - Make install prefix optional - Improve README --- modules/cmake/README.md | 11 +++++++---- modules/cmake/init.zsh | 33 ++++++++++++++++++++++----------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/modules/cmake/README.md b/modules/cmake/README.md index a787bf44..d30d476a 100644 --- a/modules/cmake/README.md +++ b/modules/cmake/README.md @@ -15,16 +15,19 @@ $ mb -DSOME_EXTRA_FLAGS="foo" ### Options ```sh -# Set the install prefix. +# Set the install prefix (else CMake's default prefix will be used) zstyle ':prezto:module:cmake' install-prefix '/usr' -# Set the build prefix. +# Set the build prefix (else '_build' will be used) zstyle ':prezto:module:cmake' build-prefix '_build' -# Set the build profiles. +# Set the build profiles (else Debug and Release will be used) zstyle ':prezto:module:cmake' profiles 'Debug' 'Release' -# Whether to support clang as well. +# Set the generator (else CMake's default generator will be used) +zstyle ':prezto:module:cmake' generator 'Unix Makefiles' + +# Whether to support clang as well (default is 'yes') zstyle ':prezto:module:cmake' support-clang 'yes' ``` diff --git a/modules/cmake/init.zsh b/modules/cmake/init.zsh index 61b31b82..4a7e829f 100644 --- a/modules/cmake/init.zsh +++ b/modules/cmake/init.zsh @@ -6,9 +6,9 @@ # Thomas Moulard # -# Get the install prefix or use the default. +# Get the install prefix. zstyle -s ':prezto:module:cmake' install-prefix '_cmake_install_prefix' \ - || _cmake_install_prefix='/usr' + || _cmake_install_prefix= # Get the build prefix. zstyle -s ':prezto:module:cmake' build-prefix '_cmake_build_prefix' \ @@ -18,11 +18,15 @@ zstyle -s ':prezto:module:cmake' build-prefix '_cmake_build_prefix' \ zstyle -a ':prezto:module:cmake' profiles '_cmake_profiles' \ || _cmake_profiles=(Debug Release) +# Get the generator to use. +zstyle -s ':prezto:module:cmake' generator '_cmake_generator' \ + || _cmake_generator= + # Whether to look for clang as well. zstyle -b ':prezto:module:cmake' support-clang '_cmake_support_clang' \ || _cmake_support_clang=true -# Check for clang +# Check for clang. _cmake_has_clang=false if (( ${_cmake_support_clang} && $+commands[clang] )); then _cmake_has_clang=true @@ -38,16 +42,25 @@ function makeBuildDirectory return 1 fi - local common_flags="-DCMAKE_INSTALL_PREFIX=${_cmake_install_prefix}" + local common_flags="" + + # If an install prefix was provided. + if [[ ! -z "${_cmake_install_prefix}" ]]; then + common_flags+=" -DCMAKE_INSTALL_PREFIX=\"${_cmake_install_prefix}\"" + fi + + # If a generator was provided. + if [[ ! -z "${_cmake_generator}" ]]; then + common_flags+=" -G\"${_cmake_generator}\"" + fi # Create default GCC profiles. for p in "${_cmake_profiles[@]}"; do echo "*** Creating ${p:l} profile..." local build_dir="${d}/${_cmake_build_prefix}/${p:l}" + local cmake_cmd="cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \"${d}\"" mkdir -p "${build_dir}" - (cd "${build_dir}" && \ - cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \ - "${d}") + (cd "${build_dir}" && eval ${cmake_cmd}) echo "*** ...done!" done @@ -56,11 +69,9 @@ function makeBuildDirectory for p in "${_cmake_profiles[@]}"; do echo "*** Creating ${p:l} profile (clang)..." local build_dir="${d}/${_cmake_build_prefix}/clang+${p:l}" + local cmake_cmd="cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \"${d}\"" mkdir -p "${build_dir}" - (cd "${build_dir}" && \ - CC=clang CXX=clang++ \ - cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \ - "${d}") + (cd "${build_dir}" && CC=clang CXX=clang++ eval ${cmake_cmd}) echo "*** ...done!" done fi