jedisct1 / libhydrogen

A lightweight, secure, easy-to-use crypto library suitable for constrained environments.
https://libhydrogen.org
Other
631 stars 94 forks source link

Fix cmake not found error #72

Closed myd7349 closed 5 years ago

myd7349 commented 5 years ago

When I was trying to add libhydrogen into vcpkg(https://github.com/microsoft/vcpkg/pull/7436), the vcpkg's CI system reports it fails on Linux and macOS: https://dev.azure.com/vcpkg/public/_build/results?buildId=8415 https://dev.azure.com/vcpkg/public/_build/results?buildId=8418 I downloaded the port failure logs and got this:

[1/6] /usr/bin/cc -I/home/vcpkg/myagent/_work/4/s/buildtrees/libhydrogen/src/a1d93becec-95c16f0d25 -fPIC -g -Os -march=native -fno-exceptions -Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wno-type-limits -MD -MT CMakeFiles/hydrogen-tests.dir/tests/tests.c.o -MF CMakeFiles/hydrogen-tests.dir/tests/tests.c.o.d -o CMakeFiles/hydrogen-tests.dir/tests/tests.c.o -c /home/vcpkg/myagent/_work/4/s/buildtrees/libhydrogen/src/a1d93becec-95c16f0d25/tests/tests.c [2/6] /usr/bin/cc -I/home/vcpkg/myagent/_work/4/s/buildtrees/libhydrogen/src/a1d93becec-95c16f0d25 -fPIC -g -Os -march=native -fno-exceptions -Wall -Wextra -Wmissing-prototypes -Wdiv-by-zero -Wbad-function-cast -Wcast-align -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wnested-externs -Wno-unknown-pragmas -Wpointer-arith -Wredundant-decls -Wstrict-prototypes -Wswitch-enum -Wno-type-limits -MD -MT CMakeFiles/hydrogen.dir/hydrogen.c.o -MF CMakeFiles/hydrogen.dir/hydrogen.c.o.d -o CMakeFiles/hydrogen.dir/hydrogen.c.o -c /home/vcpkg/myagent/_work/4/s/buildtrees/libhydrogen/src/a1d93becec-95c16f0d25/hydrogen.c [3/6] : && /home/vcpkg/myagent/_work/4/s/downloads/tools/cmake-3.14.0-linux/cmake-3.14.0-Linux-x86_64/bin/cmake -E remove libhydrogen.a && /usr/bin/ar qc libhydrogen.a CMakeFiles/hydrogen.dir/hydrogen.c.o && /usr/bin/ranlib libhydrogen.a && : [4/6] : && /usr/bin/cc -fPIC -g CMakeFiles/hydrogen-tests.dir/tests/tests.c.o -o hydrogen-tests libhydrogen.a && : [5/6] cd /mnt/buildtrees/libhydrogen/x64-linux-dbg && cmake -E remove /mnt/buildtrees/libhydrogen/x64-linux-dbg/hydrogen-run-tests.done && ctest -C Debug --output-on-failure && cmake -E touch /mnt/buildtrees/libhydrogen/x64-linux-dbg/hydrogen-run-tests.done FAILED: hydrogen-run-tests.done cd /mnt/buildtrees/libhydrogen/x64-linux-dbg && cmake -E remove /mnt/buildtrees/libhydrogen/x64-linux-dbg/hydrogen-run-tests.done && ctest -C Debug --output-on-failure && cmake -E touch /mnt/buildtrees/libhydrogen/x64-linux-dbg/hydrogen-run-tests.done /bin/sh: 1: cmake: not found ninja: build stopped: subcommand failed.

It complains that /bin/sh: 1: cmake: not found. I am not sure how is CMake installed on vcpkg's CI agents, it just does not work.

This patch uses CMake's predefined ${CMAKE_COMMAND} and ${CMAKE_CTEST_COMMAND} variables, and it works fine.

spinda commented 5 years ago

You should quote those, or there will be problems when those paths contain spaces.

myd7349 commented 5 years ago

Hi! @spinda Thanks! In fact, I quoted them at first, but unquoted them just before I created this PR since it seems CMake can handle it correctly.

On Ubuntu, the generated makefile has thses lines in it:

hydrogen-run-tests.done: hydrogen-tests
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --blue --bold --progress-dir=/home/myd/libhydrogen/build/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Generating hydrogen-run-tests.done"
    "/home/myd/cmake 3.14.0 linux/cmake-3.14.0-Linux-x86_64/bin/cmake" -E remove /home/myd/libhydrogen/build/hydrogen-run-tests.done
    "/home/myd/cmake 3.14.0 linux/cmake-3.14.0-Linux-x86_64/bin/ctest" -C  --output-on-failure
    "/home/myd/cmake 3.14.0 linux/cmake-3.14.0-Linux-x86_64/bin/cmake" -E touch /home/myd/libhydrogen/build/hydrogen-run-tests.done

On Win10, I got this in hydrogen-run-tests.vcxproj:

      <Command Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">setlocal
cd C:\Users\vcpkg\Desktop\libhydrogen\build2
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
"E:\Program Files\CMake\bin\cmake.exe" -E remove C:/Users/vcpkg/Desktop/libhydrogen/build2/hydrogen-run-tests.done
if %errorlevel% neq 0 goto :cmEnd
"E:\Program Files\CMake\bin\ctest.exe" -C RelWithDebInfo --output-on-failure
if %errorlevel% neq 0 goto :cmEnd
"E:\Program Files\CMake\bin\cmake.exe" -E touch C:/Users/vcpkg/Desktop/libhydrogen/build2/hydrogen-run-tests.done
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>

I read this post https://stackoverflow.com/questions/35847655/when-should-i-quote-variables, it also recommands to quote those file paths in add_custom_command. So I will create a new PR.

Thanks again!