1
0
Fork 0

Improve CMake module

- Add support for CMake generators
- Make install prefix optional
- Improve README
pull/1036/head
Benjamin Chrétien 9 years ago
parent 9c7f99fd17
commit 2c8ad10f2b

@ -15,16 +15,19 @@ $ mb -DSOME_EXTRA_FLAGS="foo"
### Options ### Options
```sh ```sh
# Set the install prefix. # Set the install prefix (else CMake's default prefix will be used)
zstyle ':prezto:module:cmake' install-prefix '/usr' 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' 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' 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' zstyle ':prezto:module:cmake' support-clang 'yes'
``` ```

@ -6,9 +6,9 @@
# Thomas Moulard <thomas dot moulard at gmail dot com> # Thomas Moulard <thomas dot moulard at gmail dot com>
# #
# Get the install prefix or use the default. # Get the install prefix.
zstyle -s ':prezto:module:cmake' install-prefix '_cmake_install_prefix' \ zstyle -s ':prezto:module:cmake' install-prefix '_cmake_install_prefix' \
|| _cmake_install_prefix='/usr' || _cmake_install_prefix=
# Get the build prefix. # Get the build prefix.
zstyle -s ':prezto:module:cmake' build-prefix '_cmake_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' \ zstyle -a ':prezto:module:cmake' profiles '_cmake_profiles' \
|| _cmake_profiles=(Debug Release) || _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. # Whether to look for clang as well.
zstyle -b ':prezto:module:cmake' support-clang '_cmake_support_clang' \ zstyle -b ':prezto:module:cmake' support-clang '_cmake_support_clang' \
|| _cmake_support_clang=true || _cmake_support_clang=true
# Check for clang # Check for clang.
_cmake_has_clang=false _cmake_has_clang=false
if (( ${_cmake_support_clang} && $+commands[clang] )); then if (( ${_cmake_support_clang} && $+commands[clang] )); then
_cmake_has_clang=true _cmake_has_clang=true
@ -38,16 +42,25 @@ function makeBuildDirectory
return 1 return 1
fi 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. # Create default GCC profiles.
for p in "${_cmake_profiles[@]}"; do for p in "${_cmake_profiles[@]}"; do
echo "*** Creating ${p:l} profile..." echo "*** Creating ${p:l} profile..."
local build_dir="${d}/${_cmake_build_prefix}/${p:l}" 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}" mkdir -p "${build_dir}"
(cd "${build_dir}" && \ (cd "${build_dir}" && eval ${cmake_cmd})
cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \
"${d}")
echo "*** ...done!" echo "*** ...done!"
done done
@ -56,11 +69,9 @@ function makeBuildDirectory
for p in "${_cmake_profiles[@]}"; do for p in "${_cmake_profiles[@]}"; do
echo "*** Creating ${p:l} profile (clang)..." echo "*** Creating ${p:l} profile (clang)..."
local build_dir="${d}/${_cmake_build_prefix}/clang+${p:l}" 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}" mkdir -p "${build_dir}"
(cd "${build_dir}" && \ (cd "${build_dir}" && CC=clang CXX=clang++ eval ${cmake_cmd})
CC=clang CXX=clang++ \
cmake ${common_flags} ${extra_flags} -DCMAKE_BUILD_TYPE=${p} \
"${d}")
echo "*** ...done!" echo "*** ...done!"
done done
fi fi

Loading…
Cancel
Save