node.native icon indicating copy to clipboard operation
node.native copied to clipboard

CMakeLists in node.native + seperate project?

Open AlecTaylor opened this issue 11 years ago • 2 comments

How do I setup a separate project that works with node.native (from git, not from install library locations)?

Here is what I have tried:

git clone https://github.com/d5/node.native.git
mkdir routing_tests && cd $_

Then I created main.cpp and CMakeLists.txt:

project(routing_tests)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
include_directories(../node.native/ ../node.native/native)
include_directories(../node.native/libuv ../node.native/libuv/include ../node.native/http-parser)

But unfortunately I get these errors: Qt Creator screenshot

How do I fix this? - Also, are you planning on moving from vanilla Makefiles to CMake?

AlecTaylor avatar Jan 14 '14 14:01 AlecTaylor

Hi Alec,

You'll need to link to libuv.so - you'll have to cook that into your CMakeLists.txt file.

You'll also need to link http-parser.o into your executable.

Here's how I do this for a project I've been developing where I've used autotools, so this is a Makefile.am (which gets turned into Makefile.in, then finally into a Makefile).

The program is called "dt":

===================================
AUTOMAKE_OPTIONS = check-news dist-bzip2
SUBDIRS = src
bin_PROGRAMS = dt
dt_SOURCES = dt.cpp
dt_LDADD = src/ipp/libdtipp.la /usr/local/lib/libuv.a /usr/local/lib/http_parser.o
INCLUDES = -I./usr/local/include
CLEANFILES = *~
MAINTAINERCLEANFILES = aclocal.m4 dt-*.tar.gz dt-*.tar.bz2 dt-*.diff
====================================

Note that my includes are in /usr/local/include and my libs (libuv.so and http-parser.o) are in /usr/local/lib/

I added a few lines to the node.native Makefile so that it would install the relevant files into /usr/local/include and /usr/local/lib/ on my Debian development system. This is really just a quick hack:

=========================================================
# Note: Copy in libuv and http-parser, as required with this? Will eventually make myself
# a libnative shared object?
install:
# http-parser (headers and object code)
        cp http-parser/http_parser.h /usr/local/include/
# libuv (headers and static lib)
        cp libuv/libuv.a /usr/local/lib/
        mkdir -p /usr/local/include/uv
        cp libuv/include/uv.h /usr/local/include/
        cp -Ra libuv/include/uv-private /usr/local/include/
# node.native (headers only)
        cp -Ra native /usr/local/include/
================================================

With this, I can do "make install" in node.native then go over to my "dt" directory and compile there.

Hope that helps,

Seb

sebjameswml avatar Jan 14 '14 14:01 sebjameswml

Thanks Seb, will try that tonight.

In the meantime, can you help me understand why people are writing vanilla Makefiles rather than using CMake?

Isn't one of the big advantages of libuv that it abstracts cross-platform differences?

AlecTaylor avatar Jan 15 '14 03:01 AlecTaylor