-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from nats-io/windows-port
Windows port
- Loading branch information
Showing
52 changed files
with
1,936 additions
and
1,189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
cmake_minimum_required(VERSION 2.8) | ||
|
||
project(cnats) | ||
include(CTest) | ||
|
||
# Uncomment to have the build process verbose | ||
#set(CMAKE_VERBOSE_MAKEFILE TRUE) | ||
|
||
# Uncomment to have the executable moved to 'build' instead of their respective 'build/xxx' directories | ||
#set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) | ||
|
||
# Platform specific settings | ||
if(UNIX) | ||
#--------------------------------------------------------------------------- | ||
# Define NATS cache variables that override the CMAKE and MEMCHECK variables | ||
#--------------------------------------------------------------------------- | ||
set(NATS_BUILD_TYPE Release CACHE STRING "Build type: Release, Debug, RelWithDebInfo, MinRelSize") | ||
set(CMAKE_BUILD_TYPE ${NATS_BUILD_TYPE} CACHE INTERNAL "") | ||
|
||
set(NATS_BUILD_ARCH "64" CACHE STRING "32 for 32bits builds") | ||
|
||
set(NATS_INSTALL_PREFIX ../install CACHE PATH "Install prefix") | ||
set(CMAKE_INSTALL_PREFIX ${NATS_INSTALL_PREFIX} CACHE INTERNAL "") | ||
|
||
set(NATS_MEMCHECK_CMD "/usr/bin/valgrind" CACHE FILE "Memcheck tool") | ||
set(MEMORYCHECK_COMMAND ${NATS_MEMCHECK_CMD} CACHE INTERNAL "") | ||
|
||
set(NATS_MEMCHECK_CMD_OPTS "--leak-check=full --track-fds=yes --show-reachable=yes --num-callers=50" CACHE STRING "Memcheck options") | ||
set(MEMORYCHECK_COMMAND_OPTIONS ${NATS_MEMCHECK_CMD_OPTS} CACHE INTERNAL "") | ||
|
||
set(NATS_SUPPRESSIONS_FILE ${PROJECT_SOURCE_DIR}/test/valgrind.sup CACHE FILE "Suppressions file") | ||
set(MEMORYCHECK_SUPPRESSIONS_FILE ${NATS_SUPPRESSIONS_FILE} CACHE INTERNAL "") | ||
|
||
set(NATS_COMMON_C_FLAGS "-std=c99 -pedantic") | ||
|
||
if(NATS_BUILD_TYPE MATCHES "Debug") | ||
set(NATS_COMMON_C_FLAGS "${NATS_COMMON_C_FLAGS} -ggdb") | ||
endif(NATS_BUILD_TYPE MATCHES "Debug") | ||
|
||
set(NATS_WARNINGS "-Wall -W -Wno-unused-variable -Wno-unused-parameter -Wno-unused-function -Wstrict-prototypes -Wwrite-strings") | ||
set(NATS_PLATFORM_INCLUDE "unix") | ||
|
||
if(APPLE) | ||
set(CMAKE_MACOSX_RPATH OFF) | ||
set(NATS_OS "DARWIN") | ||
else(APPLE) | ||
set(NATS_OS "LINUX") | ||
set(NATS_USE_PTHREAD "-pthread") | ||
endif(APPLE) | ||
|
||
if (${NATS_BUILD_ARCH} MATCHES "32") | ||
if(NOT APPLE) | ||
message("-----------------------------------------------------------") | ||
message("If build fails, you probably need to install libc6-dev-i386") | ||
message("apt-get install libc6-dev-i386") | ||
message("-----------------------------------------------------------") | ||
endif(NOT APPLE) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -m32") | ||
set(CMAKE_C_LINKER_FLAGS "${CMAKE_C_LINKER_FLAGS} -m32") | ||
endif(${NATS_BUILD_ARCH} MATCHES "32") | ||
|
||
elseif(WIN32) | ||
set(NATS_OS "_WIN32") | ||
set(NATS_PLATFORM_INCLUDE "win") | ||
endif(UNIX) | ||
|
||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NATS_COMMON_C_FLAGS} ${NATS_USE_PTHREAD} ${NATS_WARNINGS}") | ||
|
||
add_definitions(-D${NATS_OS}) | ||
add_definitions(-D_REENTRANT) | ||
|
||
#--------------------------------------------------------------------- | ||
# Add to the 'clean' target the list (and location) of files to remove | ||
|
||
list(APPEND NATS_INSTALLED_FILES "${CMAKE_INSTALL_PREFIX}/include/nats.h") | ||
list(APPEND NATS_INSTALLED_FILES "${CMAKE_INSTALL_PREFIX}/include/status.h") | ||
list(APPEND NATS_INSTALLED_FILES "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}nats_static${CMAKE_STATIC_LIBRARY_SUFFIX}") | ||
list(APPEND NATS_INSTALLED_FILES "${CMAKE_INSTALL_PREFIX}/lib/${CMAKE_SHARED_LIBRARY_PREFIX}nats${CMAKE_SHARED_LIBRARY_SUFFIX}") | ||
|
||
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${NATS_INSTALLED_FILES}") | ||
#--------------------------------------------------------------------- | ||
|
||
#---------------------------- | ||
# Add the project directories | ||
|
||
add_subdirectory(src) | ||
add_subdirectory(examples) | ||
add_subdirectory(test) | ||
#---------------------------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,38 +12,123 @@ First, download the source code: | |
git clone [email protected]:nats-io/cnats.git . | ||
``` | ||
|
||
Then, build the library: | ||
To build the library, use [CMake](https://cmake.org/download/). Go into the `build` directory and issue this command for the first time: | ||
|
||
``` | ||
make install examples | ||
cmake .. | ||
``` | ||
|
||
This will build both the static and dynamic libraries and the examples binaries. After this step, the directory `install` contains two folders: `include` and `lib`, where the header files necessary for your application to use the C NATS library are located, and where the compiled libraries are located. | ||
or use the GUI to setup the way you want. When you are satified with the settings, simply invoke: | ||
|
||
You have several targets to pass to the make command. Here is a list: | ||
``` | ||
make | ||
``` | ||
|
||
on Windows, you may do this for example: | ||
|
||
``` | ||
cmake --build . --config "Release" | ||
``` | ||
|
||
This is building the static and shared libraries and also the examples and the test program. Each are located in their respective directories under `build`: `src`, `examples` and `test`. | ||
|
||
``` | ||
make install | ||
``` | ||
|
||
Will copy both the static and shared libraries in the folder `install/lib` and the public headers in `install/include`. | ||
|
||
You can list all the possible `make` options with the command: | ||
|
||
``` | ||
make help | ||
``` | ||
|
||
The most common you will use are: | ||
|
||
* clean | ||
* install | ||
* examples | ||
* test | ||
|
||
You can compile in debug mode and/or in 32 bits using the command line parameters: | ||
On platforms where `valgrind` is available, you can run the tests with memory checks. | ||
Here is an example: | ||
|
||
``` | ||
make test ARGS="-T memcheck" | ||
``` | ||
|
||
* debug | ||
* m | ||
Or, you can invoke directly the `ctest` program: | ||
|
||
Here is an example: | ||
``` | ||
ctest -T memcheck -V -I 1,4 | ||
``` | ||
The above command would run the tests with `valgrind` (`-T memcheck`), with verbose output (`-V`), and run the tests from 1 to 4 (`-I 1,4`). | ||
|
||
If you add a test to `test/test.c`, you need to add it into the `allTests` array. Each entry contains a name, and the test function. You can add it anywhere into this array. | ||
Build you changes: | ||
|
||
``` | ||
make debug=on m=32 | ||
$ make | ||
[ 44%] Built target nats | ||
[ 88%] Built target nats_static | ||
[ 90%] Built target nats-publisher | ||
[ 92%] Built target nats-queuegroup | ||
[ 94%] Built target nats-replier | ||
[ 96%] Built target nats-requestor | ||
[ 98%] Built target nats-subscriber | ||
Scanning dependencies of target testsuite | ||
[100%] Building C object test/CMakeFiles/testsuite.dir/test.c.o | ||
Linking C executable testsuite | ||
[100%] Built target testsuite | ||
``` | ||
|
||
We recommand that your run the test suite to ensure that everything works fine in your environment | ||
Now regenerate the list by invoking the test suite without any argument: | ||
|
||
``` | ||
make test | ||
$ ./test/testsuite | ||
Number of tests: 77 | ||
``` | ||
|
||
This list the number of tests added to the file `list.txt`. Move this file to the source's test directory. | ||
|
||
``` | ||
$ mv list.txt ../test/ | ||
``` | ||
|
||
Then, refresh the build: | ||
|
||
``` | ||
$ cmake .. | ||
-- Configuring done | ||
-- Generating done | ||
-- Build files have been written to: /home/ivan/cnats/build | ||
``` | ||
|
||
You can use the following environment variables to influence the testsuite behavior. | ||
|
||
When running with memory check, timing changes and overall performance is slower. The following variable allows the testsuite to adjust some of values used during the test: | ||
|
||
``` | ||
NATS_TEST_VALGRIND=yes | ||
``` | ||
|
||
When running the tests in verbose mode, the following environment variable allows you to see the server output from within the test itself. Without this option, the server output is silenced: | ||
|
||
``` | ||
NATS_TEST_KEEP_SERVER_OUTPUT=yes | ||
``` | ||
|
||
If you want to change the default server executable name (`gnastd`) or specify a specific location, use this environment variable: | ||
|
||
``` | ||
NATS_TEST_SERVER_EXE=<full server executable path> | ||
for instance: | ||
NATS_TEST_SERVER_EXE=c:\test\gnatsd.exe | ||
``` | ||
|
||
|
||
## Basic Usage | ||
|
||
Note that for simplicity, error checking is not performed here. | ||
|
Oops, something went wrong.