Skip to content

Conversation

@bnoordhuis
Copy link
Member

All good things come in threes and that's why besides autotools and gyp,
you can now also build everyone's favorite platform abstraction library
with cmake.

This is Ouroboros eating its own tail in a way because cmake depends on
libuv, depends on cmake, depends on libuv, depends on... inception!

Things it does:

  • build the shared library
  • build the static library
  • install the shared library
  • install the static library
  • install the header files
  • install libuv.pc

Things it does not yet do:

  • build or install the documentation
  • build or execute the test suite
  • produce a release tarball
  • provide auto-config for downstream cmake-based projects

Fixes: #1362

The last commit adds support for running tests through ctest(1). It's not super fancy yet but it works.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for breaking this up into small commits :-D

LGTM as best I can tell.

@bnoordhuis bnoordhuis mentioned this pull request May 28, 2018
@ghost
Copy link

ghost commented May 28, 2018

Looks great! I have a few nitpicks.

  1. I would have used target_compile_options instead of CMAKE_C_FLAGS, as per the usual recommendations for using modern CMake. It's kind of harmless in this case, though, since all the targets probably use the same flags anyway.
  2. Naming the test program uv-test or uv_test may be more appropriate. I would avoid using test as a target name because a) it exists as a phony Makefile target and b) it may conflict with other target names if libuv is included by another project with add_subdirectory.
  3. Although this may be more of an opinion, I wouldn't build both the static and shared version of the library like that. The BUILD_SHARED_LIBS variable serves that purpose of allowing the user to decide which kind of library to build. At the very least, if you don't like that approach, I would allow the user to specify whether or not to build one library or the other (or both.)

@piscisaureus
Copy link
Contributor

I'm on Windows; installing libraries isn't really a thing I expect to do. Is there a way to configure without?

C:\Users\BertBelder\d\libuv2>cmake.exe -G "Visual Studio 15 2017 Win64"
-- The CXX compiler identification is MSVC 19.14.26428.1
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/Preview/Enterprise/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/Preview/Enterprise/VC/Tools/MSVC/14.14.26428/bin/Hostx86/x64/cl.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:366 (install):
  install Library TARGETS given no DESTINATION!

@piscisaureus
Copy link
Contributor

With this simple patch applied, it passes the configuration stage:

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bd101ad4..4bfd7574 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -360,8 +360,10 @@ set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
 set(prefix ${CMAKE_INSTALL_PREFIX})
 configure_file(libuv.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libuv.pc @ONLY)

-install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
-install(FILES LICENSE ${CMAKE_CURRENT_BINARY_DIR}/libuv.pc
-        DESTINATION ${CMAKE_INSTALL_DOCDIR})
-install(TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
-install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+if (DESTINATION)
+  install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+  install(FILES LICENSE ${CMAKE_CURRENT_BINARY_DIR}/libuv.pc
+          DESTINATION ${CMAKE_INSTALL_DOCDIR})
+  install(TARGETS uv LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+  install(TARGETS uv_a ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
+endif(DESTINATION)

@piscisaureus
Copy link
Contributor

It's a little strange that the generated project has both a RUN_TESTS and run-tests target, but I couldn't figure out why that happens.

@piscisaureus
Copy link
Contributor

As far as building is concerned - it bows out on not being able to find tree.h:

C:\Users\BertBelder\d\libuv2>cmake --build . --target run-tests
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 5/28/2018 3:30:17 PM.
Project "C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" on node 1 (default targets).
Project "C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" (1) is building "C:\Users\BertBelder\d\libuv2\ZERO_CHECK.vcxpr
oj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\Users\BertBelder\d\libuv2\ZERO_CHECK.vcxproj" (default targets).

Project "C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" (1) is building "C:\Users\BertBelder\d\libuv2\uv_a.vcxproj" (3
) on node 1 (default targets).
InitializeBuildStatus:
  Touching "uv_a.dir\Debug\uv_a.tlog\unsuccessfulbuild".
CustomBuild:
  All outputs are up-to-date.
ClCompile:
  C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\CL.exe /c
   /IC:\Users\BertBelder\d\libuv2\include /IC:\Users\BertBelder\d\libuv2\src /Zi /nologo /W4 /WX- /diagnostics:classic
  /Od /Ob0 /D WIN32 /D _WINDOWS /D _DEBUG /D WIN32_LEAN_AND_MEAN /D _WIN32_WINNT=0x0600 /D "CMAKE_INTDIR=\"Debug\"" /D
  _MBCS /Gm- /RTC1 /MDd /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"uv_a.dir\Debug\\" /Fd"uv_a.dir\Debug\uv
  _a.pdb" /Gd /TC /FC /errorReport:queue C:\Users\BertBelder\d\libuv2\src\win\timer.c
  timer.c
c:\users\bertbelder\d\libuv2\src\win\winapi.h(4152): warning C4201: nonstandard extension used: nameless struct/union [
C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]
c:\users\bertbelder\d\libuv2\src\win\winapi.h(4160): warning C4201: nonstandard extension used: nameless struct/union [
C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]
c:\users\bertbelder\d\libuv2\src\win\timer.c(27): fatal error C1083: Cannot open include file: 'tree.h': No such file o
r directory [C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]
Done Building Project "C:\Users\BertBelder\d\libuv2\uv_a.vcxproj" (default targets) -- FAILED.

Done Building Project "C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" (default targets) -- FAILED.


Build FAILED.

"C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" (default target) (1) ->
"C:\Users\BertBelder\d\libuv2\uv_a.vcxproj" (default target) (3) ->
(ClCompile target) ->
  c:\users\bertbelder\d\libuv2\src\win\winapi.h(4152): warning C4201: nonstandard extension used: nameless struct/union
 [C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]
  c:\users\bertbelder\d\libuv2\src\win\winapi.h(4160): warning C4201: nonstandard extension used: nameless struct/union
 [C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]


"C:\Users\BertBelder\d\libuv2\run-tests.vcxproj" (default target) (1) ->
"C:\Users\BertBelder\d\libuv2\uv_a.vcxproj" (default target) (3) ->
(ClCompile target) ->
  c:\users\bertbelder\d\libuv2\src\win\timer.c(27): fatal error C1083: Cannot open include file: 'tree.h': No such file
 or directory [C:\Users\BertBelder\d\libuv2\uv_a.vcxproj]

    2 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.09

Which can be solved with:

diff --git a/src/win/timer.c b/src/win/timer.c
index 7e006fed..eda5c24f 100644
--- a/src/win/timer.c
+++ b/src/win/timer.c
@@ -24,7 +24,7 @@

 #include "uv.h"
 #include "internal.h"
-#include "tree.h"
+#include "uv/tree.h"
 #include "handle-inl.h"

@bnoordhuis bnoordhuis force-pushed the cmake branch 2 times, most recently from 144fa68 to a24b737 Compare May 30, 2018 12:42
@bnoordhuis
Copy link
Member Author

Suggestions and fixes included. CI: https://ci.nodejs.org/view/libuv/job/libuv-test-commit/889/

  • switched to target_compile_option
  • renamed the test targets
  • wrapped install() commands in if(UNIX)
  • fixed include

Apropos BUILD_SHARED_LIBS, I decided not to use that because because then you can't test the static and shared library builds at the same time.

@@ -0,0 +1,381 @@
# TODO: determine CMAKE_SYSTEM_NAME on OS/390. Currently assumes "OS/390".
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jBarz Do you happen to know?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is OS/390

@piscisaureus
Copy link
Contributor

piscisaureus commented May 30, 2018

cmake.exe . -G "Visual Studio 15 2017 Win64" -DBUILD_TESTING=ON

Configuration works!
I don't like it super much that the test target isn't configured unless I set BUILD_TESTING=ON. Isn't it possible to always configure the tests, just not always build it?

Building the tests fails now:
C:\Users\BertBelder\d\libuv2>cmake.exe --build . --target uv_run_tests
Microsoft (R) Build Engine version 15.7.177.53362 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 5/30/2018 1:49:11 PM.
Project "C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj" on node 1 (default targets).
Project "C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj" (1) is building "C:\Users\BertBelder\d\libuv2\ZERO_CHECK.vc
xproj" (2) on node 1 (default targets).
InitializeBuildStatus:
  Creating "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
  All outputs are up-to-date.
FinalizeBuildStatus:
  Deleting file "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\unsuccessfulbuild".
  Touching "x64\Debug\ZERO_CHECK\ZERO_CHECK.tlog\ZERO_CHECK.lastbuildstate".
Done Building Project "C:\Users\BertBelder\d\libuv2\ZERO_CHECK.vcxproj" (default targets).

Project "C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj" (1) is building "C:\Users\BertBelder\d\libuv2\uv.vcxproj" (
3) on node 1 (default targets).
InitializeBuildStatus:
  Creating "uv.dir\Debug\uv.tlog\unsuccessfulbuild" because "AlwaysCreate" was specified.
CustomBuild:
  All outputs are up-to-date.
ClCompile:
  All outputs are up-to-date.
Link:
  All outputs are up-to-date.
  uv.vcxproj -> C:\Users\BertBelder\d\libuv2\Debug\uv.dll
FinalizeBuildStatus:
  Deleting file "uv.dir\Debug\uv.tlog\unsuccessfulbuild".
  Touching "uv.dir\Debug\uv.tlog\uv.lastbuildstate".
Done Building Project "C:\Users\BertBelder\d\libuv2\uv.vcxproj" (default targets).

InitializeBuildStatus:
  Touching "uv_run_tests.dir\Debug\uv_run_tests.tlog\unsuccessfulbuild".
CustomBuild:
  All outputs are up-to-date.
ClCompile:
  All outputs are up-to-date.
Link:
  C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\VC\Tools\MSVC\14.14.26428\bin\HostX86\x64\link.exe
  /ERRORREPORT:QUEUE /OUT:"C:\Users\BertBelder\d\libuv2\Debug\uv_run_tests.exe" /INCREMENTAL /NOLOGO kernel32.lib user3
  2.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib Debug\uv.lib ws2_3
  2.lib advapi32.lib iphlpapi.lib psapi.lib shell32.lib user32.lib userenv.lib ws2_32.lib /MANIFEST /MANIFESTUAC:"level
  ='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:/Users/BertBelder/d/libuv2/Debug/uv_run_tests.pdb" /SUB
  SYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:/Users/BertBelder/d/libuv2/Debug/uv_run_tests.lib" /MACHINE
  :X64  /machine:x64 "uv_run_tests.dir\Debug\blackhole-server.obj"
  "uv_run_tests.dir\Debug\echo-server.obj"
  "uv_run_tests.dir\Debug\run-tests.obj"
  uv_run_tests.dir\Debug\runner.obj
  "uv_run_tests.dir\Debug\test-active.obj"
  "uv_run_tests.dir\Debug\test-async-null-cb.obj"
  "uv_run_tests.dir\Debug\test-async.obj"
  "uv_run_tests.dir\Debug\test-barrier.obj"
  "uv_run_tests.dir\Debug\test-callback-order.obj"
  "uv_run_tests.dir\Debug\test-callback-stack.obj"
  "uv_run_tests.dir\Debug\test-close-fd.obj"
  "uv_run_tests.dir\Debug\test-close-order.obj"
  "uv_run_tests.dir\Debug\test-condvar.obj"
  "uv_run_tests.dir\Debug\test-connect-unspecified.obj"
  "uv_run_tests.dir\Debug\test-connection-fail.obj"
  "uv_run_tests.dir\Debug\test-cwd-and-chdir.obj"
  "uv_run_tests.dir\Debug\test-default-loop-close.obj"
  "uv_run_tests.dir\Debug\test-delayed-accept.obj"
  "uv_run_tests.dir\Debug\test-dlerror.obj"
  "uv_run_tests.dir\Debug\test-eintr-handling.obj"
  "uv_run_tests.dir\Debug\test-embed.obj"
  "uv_run_tests.dir\Debug\test-emfile.obj"
  "uv_run_tests.dir\Debug\test-env-vars.obj"
  "uv_run_tests.dir\Debug\test-error.obj"
  "uv_run_tests.dir\Debug\test-fail-always.obj"
  "uv_run_tests.dir\Debug\test-fork.obj"
  "uv_run_tests.dir\Debug\test-fs-copyfile.obj"
  "uv_run_tests.dir\Debug\test-fs-event.obj"
  "uv_run_tests.dir\Debug\test-fs-poll.obj"
  "uv_run_tests.dir\Debug\test-fs.obj"
  "uv_run_tests.dir\Debug\test-get-currentexe.obj"
  "uv_run_tests.dir\Debug\test-get-loadavg.obj"
  "uv_run_tests.dir\Debug\test-get-memory.obj"
  "uv_run_tests.dir\Debug\test-get-passwd.obj"
  "uv_run_tests.dir\Debug\test-getaddrinfo.obj"
  "uv_run_tests.dir\Debug\test-gethostname.obj"
  "uv_run_tests.dir\Debug\test-getnameinfo.obj"
  "uv_run_tests.dir\Debug\test-getsockname.obj"
  "uv_run_tests.dir\Debug\test-getters-setters.obj"
  "uv_run_tests.dir\Debug\test-handle-fileno.obj"
  "uv_run_tests.dir\Debug\test-homedir.obj"
  "uv_run_tests.dir\Debug\test-hrtime.obj"
  "uv_run_tests.dir\Debug\test-idle.obj"
  "uv_run_tests.dir\Debug\test-ip4-addr.obj"
  "uv_run_tests.dir\Debug\test-ip6-addr.obj"
  "uv_run_tests.dir\Debug\test-ipc-heavy-traffic-deadlock-bug.obj"
  "uv_run_tests.dir\Debug\test-ipc-send-recv.obj"
  "uv_run_tests.dir\Debug\test-ipc.obj"
  "uv_run_tests.dir\Debug\test-loop-alive.obj"
  "uv_run_tests.dir\Debug\test-loop-close.obj"
  "uv_run_tests.dir\Debug\test-loop-configure.obj"
  "uv_run_tests.dir\Debug\test-loop-handles.obj"
  "uv_run_tests.dir\Debug\test-loop-stop.obj"
  "uv_run_tests.dir\Debug\test-loop-time.obj"
  "uv_run_tests.dir\Debug\test-multiple-listen.obj"
  "uv_run_tests.dir\Debug\test-mutexes.obj"
  "uv_run_tests.dir\Debug\test-osx-select.obj"
  "uv_run_tests.dir\Debug\test-pass-always.obj"
  "uv_run_tests.dir\Debug\test-ping-pong.obj"
  "uv_run_tests.dir\Debug\test-pipe-bind-error.obj"
  "uv_run_tests.dir\Debug\test-pipe-close-stdout-read-stdin.obj"
  "uv_run_tests.dir\Debug\test-pipe-connect-error.obj"
  "uv_run_tests.dir\Debug\test-pipe-connect-multiple.obj"
  "uv_run_tests.dir\Debug\test-pipe-connect-prepare.obj"
  "uv_run_tests.dir\Debug\test-pipe-getsockname.obj"
  "uv_run_tests.dir\Debug\test-pipe-pending-instances.obj"
  "uv_run_tests.dir\Debug\test-pipe-sendmsg.obj"
  "uv_run_tests.dir\Debug\test-pipe-server-close.obj"
  "uv_run_tests.dir\Debug\test-pipe-set-fchmod.obj"
  "uv_run_tests.dir\Debug\test-pipe-set-non-blocking.obj"
  "uv_run_tests.dir\Debug\test-platform-output.obj"
  "uv_run_tests.dir\Debug\test-poll-close-doesnt-corrupt-stack.obj"
  "uv_run_tests.dir\Debug\test-poll-close.obj"
  "uv_run_tests.dir\Debug\test-poll-closesocket.obj"
  "uv_run_tests.dir\Debug\test-poll-oob.obj"
  "uv_run_tests.dir\Debug\test-poll.obj"
  "uv_run_tests.dir\Debug\test-process-title-threadsafe.obj"
  "uv_run_tests.dir\Debug\test-process-title.obj"
  "uv_run_tests.dir\Debug\test-queue-foreach-delete.obj"
  "uv_run_tests.dir\Debug\test-ref.obj"
  "uv_run_tests.dir\Debug\test-run-nowait.obj"
  "uv_run_tests.dir\Debug\test-run-once.obj"
  "uv_run_tests.dir\Debug\test-semaphore.obj"
  "uv_run_tests.dir\Debug\test-shutdown-close.obj"
  "uv_run_tests.dir\Debug\test-shutdown-eof.obj"
  "uv_run_tests.dir\Debug\test-shutdown-twice.obj"
  "uv_run_tests.dir\Debug\test-signal-multiple-loops.obj"
  "uv_run_tests.dir\Debug\test-signal.obj"
  "uv_run_tests.dir\Debug\test-socket-buffer-size.obj"
  "uv_run_tests.dir\Debug\test-spawn.obj"
  "uv_run_tests.dir\Debug\test-stdio-over-pipes.obj"
  "uv_run_tests.dir\Debug\test-tcp-alloc-cb-fail.obj"
  "uv_run_tests.dir\Debug\test-tcp-bind-error.obj"
  "uv_run_tests.dir\Debug\test-tcp-bind6-error.obj"
  "uv_run_tests.dir\Debug\test-tcp-close-accept.obj"
  "uv_run_tests.dir\Debug\test-tcp-close-while-connecting.obj"
  "uv_run_tests.dir\Debug\test-tcp-close.obj"
  "uv_run_tests.dir\Debug\test-tcp-connect-error-after-write.obj"
  "uv_run_tests.dir\Debug\test-tcp-connect-error.obj"
  "uv_run_tests.dir\Debug\test-tcp-connect-timeout.obj"
  "uv_run_tests.dir\Debug\test-tcp-connect6-error.obj"
  "uv_run_tests.dir\Debug\test-tcp-create-socket-early.obj"
  "uv_run_tests.dir\Debug\test-tcp-flags.obj"
  "uv_run_tests.dir\Debug\test-tcp-oob.obj"
  "uv_run_tests.dir\Debug\test-tcp-open.obj"
  "uv_run_tests.dir\Debug\test-tcp-read-stop.obj"
  "uv_run_tests.dir\Debug\test-tcp-shutdown-after-write.obj"
  "uv_run_tests.dir\Debug\test-tcp-try-write.obj"
  "uv_run_tests.dir\Debug\test-tcp-unexpected-read.obj"
  "uv_run_tests.dir\Debug\test-tcp-write-after-connect.obj"
  "uv_run_tests.dir\Debug\test-tcp-write-fail.obj"
  "uv_run_tests.dir\Debug\test-tcp-write-queue-order.obj"
  "uv_run_tests.dir\Debug\test-tcp-write-to-half-open-connection.obj"
  "uv_run_tests.dir\Debug\test-tcp-writealot.obj"
  "uv_run_tests.dir\Debug\test-thread-equal.obj"
  "uv_run_tests.dir\Debug\test-thread.obj"
  "uv_run_tests.dir\Debug\test-threadpool-cancel.obj"
  "uv_run_tests.dir\Debug\test-threadpool.obj"
  "uv_run_tests.dir\Debug\test-timer-again.obj"
  "uv_run_tests.dir\Debug\test-timer-from-check.obj"
  "uv_run_tests.dir\Debug\test-timer.obj"
  "uv_run_tests.dir\Debug\test-tmpdir.obj"
  "uv_run_tests.dir\Debug\test-tty.obj"
  "uv_run_tests.dir\Debug\test-udp-alloc-cb-fail.obj"
  "uv_run_tests.dir\Debug\test-udp-bind.obj"
  "uv_run_tests.dir\Debug\test-udp-create-socket-early.obj"
  "uv_run_tests.dir\Debug\test-udp-dgram-too-big.obj"
  "uv_run_tests.dir\Debug\test-udp-ipv6.obj"
  "uv_run_tests.dir\Debug\test-udp-multicast-interface.obj"
  "uv_run_tests.dir\Debug\test-udp-multicast-interface6.obj"
  "uv_run_tests.dir\Debug\test-udp-multicast-join.obj"
  "uv_run_tests.dir\Debug\test-udp-multicast-join6.obj"
  "uv_run_tests.dir\Debug\test-udp-multicast-ttl.obj"
  "uv_run_tests.dir\Debug\test-udp-open.obj"
  "uv_run_tests.dir\Debug\test-udp-options.obj"
  "uv_run_tests.dir\Debug\test-udp-send-and-recv.obj"
  "uv_run_tests.dir\Debug\test-udp-send-hang-loop.obj"
  "uv_run_tests.dir\Debug\test-udp-send-immediate.obj"
  "uv_run_tests.dir\Debug\test-udp-send-unreachable.obj"
  "uv_run_tests.dir\Debug\test-udp-try-send.obj"
  "uv_run_tests.dir\Debug\test-walk-handles.obj"
  "uv_run_tests.dir\Debug\test-watcher-cross-stop.obj"
  uv_run_tests.dir\Debug\snprintf.obj
  "uv_run_tests.dir\Debug\runner-win.obj"
test-spawn.obj : error LNK2019: unresolved external symbol make_program_args referenced in function run_test_argument_e
scaping [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
test-spawn.obj : error LNK2019: unresolved external symbol quote_cmd_arg referenced in function run_test_argument_escap
ing [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
test-spawn.obj : error LNK2019: unresolved external symbol make_program_env referenced in function run_test_environment
_creation [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
C:\Users\BertBelder\d\libuv2\Debug\uv_run_tests.exe : fatal error LNK1120: 3 unresolved externals [C:\Users\BertBelder\
d\libuv2\uv_run_tests.vcxproj]
Done Building Project "C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj" (default targets) -- FAILED.


Build FAILED.

"C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj" (default target) (1) ->
(Link target) ->
  test-spawn.obj : error LNK2019: unresolved external symbol make_program_args referenced in function run_test_argument
_escaping [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
  test-spawn.obj : error LNK2019: unresolved external symbol quote_cmd_arg referenced in function run_test_argument_esc
aping [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
  test-spawn.obj : error LNK2019: unresolved external symbol make_program_env referenced in function run_test_environme
nt_creation [C:\Users\BertBelder\d\libuv2\uv_run_tests.vcxproj]
  C:\Users\BertBelder\d\libuv2\Debug\uv_run_tests.exe : fatal error LNK1120: 3 unresolved externals [C:\Users\BertBelde
r\d\libuv2\uv_run_tests.vcxproj]

    0 Warning(s)
    4 Error(s)

Time Elapsed 00:00:03.77

@@ -0,0 +1,381 @@
# TODO: determine CMAKE_SYSTEM_NAME on OS/390. Currently assumes "OS/390".
cmake_minimum_required(VERSION 3.0)
project(libuv)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change the project name to be "uv" rather than "libuv". This is more in line with what the gyp build does.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I surveyed what other cmake-based projects call their libraries and 'libfoo' - not 'foo' - seems to be the standard.

@refack
Copy link
Contributor

refack commented May 30, 2018

I'm testing on Windows with the ninja generator (cmake . -G "Ninja" -DBUILD_TESTING=OFF)
Builds beautifully.

With testing on I'm getting similar results:

d:\code\4node\libuv$ ninja
[1/159] Linking C executable uv_run_tests.exe
FAILED: uv_run_tests.exe
cmd.exe /C "cd . && D:\bin\dev\cmake\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\uv_run_tests.dir --manifests  -- D:\bin\dev\VS\2017\BuildTools\VC\Tools\MSVC\14.13.26128\bin\Hostx64\x64\link.exe /nologo @CMakeFiles/uv_run_tests.rsp  /out:uv_run_tests.exe /implib:uv_run_tests.lib /pdb:uv_run_tests.pdb /version:0.0  /machine:x64 /debug /INCREMENTAL /subsystem:console  && cd ."
test-spawn.c.obj : error LNK2019: unresolved external symbol make_program_args referenced in function run_test_argument_escaping
test-spawn.c.obj : error LNK2019: unresolved external symbol quote_cmd_arg referenced in function run_test_argument_escaping
test-spawn.c.obj : error LNK2019: unresolved external symbol make_program_env referenced in function run_test_environment_creation
uv_run_tests.exe : fatal error LNK1120: 3 unresolved externals
LINK Pass 1 failed. with 1120
ninja: build stopped: subcommand failed.

IMHO targeting ninja an "official" builder will also be beneficial (simpler, faster, more predictable, less disparity with *nix, easier to integrate clcache)

@piscisaureus
Copy link
Contributor

@refack
Copy link
Contributor

refack commented May 30, 2018

@piscisaureus's patch works with ninja as well (BTW I folded your build output)

@piscisaureus
Copy link
Contributor

@refack

BTW I folded your build output

Cool, didn't know you could do that.

@mikefero
Copy link
Contributor

mikefero commented Jun 7, 2018

@bnoordhuis

I would like to suggest the following patch: bnoordhuis/libuv@cmake...mikefero:cmake

I wanted to address @piscisaureus concerns where BUILD_TESTING was not on by default and also add some installation parameters for Windows builds. I agree that the default action is to not install libraries on Windows; however for intermediate steps using CMAKE_INSTALL_PREFIX to gather all the artifacts can be handy for some users. While building the test artifacts I found an issue with the shared tests on Windows and corrected that as well (missing define USING_UV_SHARED=1).

I also corrected a build issue with older MSVC compilers and tested Visual Studio 2010 - Visual Studio 2017 (32 and 64-bit builds) and added benchmark executables to the mix as well. I understand that with libuv v2.0.0 you will be dropping support from these older compilers, but for now building against the older compilers is very handy as Visual Studio 2010/2012/2013 are not ESOL just yet (some people just can't get with the times).

@mikefero
Copy link
Contributor

mikefero commented Jun 7, 2018

To aid in evaluating the patch suggestions I updated the AppVeyor CI configuration (separate branch: mikefero/libuv@cmake...mikefero:cmake_appveyor) and executed builds against Visual Studio 2010 - Visual Studio 2017 (32 and 64-bit builds) along with GYP builds (with static library build added to the matrix). The CI run can be found here: https://ci.appveyor.com/project/mikefero/libuv/build/v1.18.0.build1.

NOTE: I also ran local builds on macOS High Sierra (10.13.4), Ubuntu 16.04, and Ubuntu 18.04 to ensure that unix-like environments were still valid with the patch suggestions.

saghul and others added 6 commits June 14, 2018 18:39
This is a cherry-pick of commit d010030 from the master branch.

Conflicts:
 	Makefile.am
 	include/uv.h
 	include/uv/unix.h
 	libuv.nsi (deleted)
 	src/unix/pthread-barrier.c (deleted)

PR-URL: libuv#1850
Reviewed-By: Colin Ihrig <[email protected]>
Move it so that include/ contains uv.h and nothing more.

PR-URL: libuv#1850
Reviewed-By: Colin Ihrig <[email protected]>
Use the right file path and variable name for the posix.h header file.

Introduced when commit ce41af2 ("cygwin: include uv-posix.h header")
was merged from the v1.x branch, where it is the correct path, into
the master branch.

This is a cherry-pick of commit d0c2ad3 from the master branch.

PR-URL: libuv#1850
Reviewed-By: Colin Ihrig <[email protected]>
MSYS2 + MinGW-w64 have good support for autoconf, that should be the
preferred way of building libuv under MinGW.

This is a cherry-pick of commit ee949df from the master branch.

PR-URL: libuv#1850
Reviewed-By: Colin Ihrig <[email protected]>
All good things come in threes and that's why besides autotools and gyp,
you can now also build everyone's favorite platform abstraction library
with cmake.

This is Ouroboros eating its own tail in a way because cmake depends on
libuv, depends on cmake, depends on libuv, depends on... inception!

Things it does:

* build the shared library
* build the static library
* install the shared library
* install the static library
* install the header files
* install libuv.pc

Things it does not yet do:

* build or install the documentation
* build or execute the test suite
* produce a release tarball
* provide auto-config for downstream cmake-based projects

Fixes: libuv#1362
PR-URL: libuv#1850
Reviewed-By: Colin Ihrig <[email protected]>
@bnoordhuis bnoordhuis closed this Jun 14, 2018
@bnoordhuis bnoordhuis deleted the cmake branch June 14, 2018 16:47
@bnoordhuis bnoordhuis merged commit 1a0f619 into libuv:v1.x Jun 14, 2018
@bnoordhuis
Copy link
Member Author

I landed this in 0cdb4a5...1a0f619 to unblock some ongoing work.

@mikefero Can you open a PR with your changes so we can discuss over coffee^Wcode? Nothing is set in stone yet so there's still room for bigger changes.

@mikefero
Copy link
Contributor

Not a problem, I will put something together this weekend (more than likely). Would you prefer them in two separate PRs since one of those commits was not related to CMake (e.g. fixed compile issue with older MSVCs)?

@bnoordhuis
Copy link
Member Author

Yes, two PRs would be best.

@refack
Copy link
Contributor

refack commented Jun 16, 2018

cjihrig added a commit to cjihrig/libuv-release-tool that referenced this pull request Jun 22, 2018
Refs: libuv/libuv#1850
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
cjihrig added a commit to cjihrig/node that referenced this pull request Jun 25, 2018
Notable changes:

- Building via cmake is now supported.
  PR-URL: libuv/libuv#1850
- Stricter checks have been added to prevent watching the same
  file descriptor multiple times.
  PR-URL: libuv/libuv#1851
  Refs: nodejs#3604
- An IPC deadlock on Windows has been fixed.
  PR-URL: libuv/libuv#1843
  Fixes: nodejs#9706
  Fixes: nodejs#7657
- uv_fs_lchown() has been added.
  PR-URL: libuv/libuv#1826
  Refs: nodejs#19868
- uv_fs_copyfile() sets errno on error.
  PR-URL: libuv/libuv#1881
  Fixes: nodejs#21329
- uv_fs_fchmod() supports -A files on Windows.
  PR-URL: libuv/libuv#1819
  Refs: nodejs#12803

PR-URL: nodejs#21466
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
targos pushed a commit to nodejs/node that referenced this pull request Jun 25, 2018
Notable changes:

- Building via cmake is now supported.
  PR-URL: libuv/libuv#1850
- Stricter checks have been added to prevent watching the same
  file descriptor multiple times.
  PR-URL: libuv/libuv#1851
  Refs: #3604
- An IPC deadlock on Windows has been fixed.
  PR-URL: libuv/libuv#1843
  Fixes: #9706
  Fixes: #7657
- uv_fs_lchown() has been added.
  PR-URL: libuv/libuv#1826
  Refs: #19868
- uv_fs_copyfile() sets errno on error.
  PR-URL: libuv/libuv#1881
  Fixes: #21329
- uv_fs_fchmod() supports -A files on Windows.
  PR-URL: libuv/libuv#1819
  Refs: #12803

PR-URL: #21466
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit to MylesBorins/node that referenced this pull request Nov 5, 2018
Notable changes:

- Building via cmake is now supported.
  PR-URL: libuv/libuv#1850
- Stricter checks have been added to prevent watching the same
  file descriptor multiple times.
  PR-URL: libuv/libuv#1851
  Refs: nodejs#3604
- An IPC deadlock on Windows has been fixed.
  PR-URL: libuv/libuv#1843
  Fixes: nodejs#9706
  Fixes: nodejs#7657
- uv_fs_lchown() has been added.
  PR-URL: libuv/libuv#1826
  Refs: nodejs#19868
- uv_fs_copyfile() sets errno on error.
  PR-URL: libuv/libuv#1881
  Fixes: nodejs#21329
- uv_fs_fchmod() supports -A files on Windows.
  PR-URL: libuv/libuv#1819
  Refs: nodejs#12803

PR-URL: nodejs#21466
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit to nodejs/node that referenced this pull request Nov 11, 2018
Notable changes:

- Building via cmake is now supported.
  PR-URL: libuv/libuv#1850
- Stricter checks have been added to prevent watching the same
  file descriptor multiple times.
  PR-URL: libuv/libuv#1851
  Refs: #3604
- An IPC deadlock on Windows has been fixed.
  PR-URL: libuv/libuv#1843
  Fixes: #9706
  Fixes: #7657
- uv_fs_lchown() has been added.
  PR-URL: libuv/libuv#1826
  Refs: #19868
- uv_fs_copyfile() sets errno on error.
  PR-URL: libuv/libuv#1881
  Fixes: #21329
- uv_fs_fchmod() supports -A files on Windows.
  PR-URL: libuv/libuv#1819
  Refs: #12803

Backport-PR-URL: #24103
PR-URL: #21466
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants