Skip to content

Commit

Permalink
Update to build procedure (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmccarthy1 authored May 20, 2020
1 parent f5e42e6 commit edb1c0b
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 100 deletions.
170 changes: 92 additions & 78 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,84 +1,98 @@
matrix:
include:
- dist: xenial
os: linux
- dist: trusty
os: linux
- dist: bionic
os: linux
- os: osx
- os: windows
language: c
sudo: required
dist: trusty
compiler: gcc

before_install:
- export FILE_ROOT="mqtt"
- export TESTS="False"
- export BUILD="True"

# Run instructions to install the C/C++ requirements (BUILD_HOME) set in place of PAHO_HOME/HDF5_HOME etc.
# Files in this case are unzipped into cbuild within travis_setup.sh
- if [[ $BUILD == "True" ]]; then
chmod +x travis_setup.sh;
./travis_setup.sh;
export BUILD_HOME=$TRAVIS_BUILD_DIR/cbuild
export LIB="cmake/$FILE_ROOT/lib";
mkdir cmake;
else
export LIB="";
fi

stages:
- build Release
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then
QLIBDIR=l64; OD=$L64;
elif [[ $TRAVIS_OS_NAME == "osx" ]]; then
QLIBDIR=m64; OD=$M64;
elif [[ $TRAVIS_OS_NAME == "windows" ]]; then
QLIBDIR=w64; OD=$W64;
else
echo "unknown OS ('$TRAVIS_OS_NAME')" >&2; exit 1;
fi

- export QLIBDIR
- mkdir qhome;
- export QHOME=$(pwd)/qhome;
- export PATH=$QHOME/$QLIBDIR:$PATH;

jobs:
include:
# Set up q for testing and execute tests on multiple
- if [[ $TESTS == "True" && "x$OD" != "x" && "x$QLIC_KC" != "x" ]]; then
export LD_LIBRARY_PATH=$BUILD_HOME/lib:$LD_LIBRARY_PATH;
export DYLD_LIBRARY_PATH=$BUILD_HOME/lib:$LD_LIBRARY_PATH;
export PATH=$BUILD_HOME/lib:$PATH;
curl -o qhome/q.zip -L $OD;
unzip -d qhome qhome/q.zip;
rm qhome/q.zip;
echo -n $QLIC_KC |base64 --decode > qhome/kc.lic;
else
echo No kdb+, no tests;
fi

- if [[ $TRAVIS_OS_NAME == "windows" ]]; then
export FILE_TAIL="zip";
else
export FILE_TAIL="tgz";
fi
- export FILE_NAME=$FILE_ROOT-$TRAVIS_OS_NAME-$TRAVIS_BRANCH.$FILE_TAIL

# LINUX BUILD
- stage: build Release
if: branch != coverity_scan
name: "Linux Build Release"
os: linux
before_install:
- mkdir paho.mqtt.c
- wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz
- tar xvf Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz -C ./paho.mqtt.c --strip-components=1
- export PAHO_HOME=$TRAVIS_BUILD_DIR/paho.mqtt.c
install:
- mkdir cmake && cd cmake && cmake ..
script:
- make install VERBOSE=1
before_deploy:
- tar -zcvf mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.tar.gz mqtt
deploy:
provider: releases
api_key: "$GITHUB_APIKEY"
file: mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.tar.gz
on:
tags: true
skip_cleanup: 'true'
# Make binaries for the library as appropriate
- if [[ $BUILD == "True" && $TRAVIS_OS_NAME == "windows" ]]; then
cd cmake && cmake -G "Visual Studio 15 2017 Win64" .. ;
export MSBUILD_PATH="/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/";
export PATH=$MSBUILD_PATH:$PATH;
MSBuild.exe INSTALL.vcxproj //m //nologo //verbosity:normal //p:Configuration=Release //p:Platform=x64;
cd ..;
elif [[ $BUILD == "True" && ( $TRAVIS_OS_NAME == "linux" || $TRAVIS_OS_NAME == "osx" ) ]]; then
cd cmake && cmake .. -DCMAKE_BUILD_TYPE=Release && make install && cd .. ;
fi

# OSX BUILD
- stage: build Release
if: branch != coverity_scan
name: "MacOS Build Release"
os: osx
before_install:
- mkdir paho.mqtt.c
- wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/Eclipse-Paho-MQTT-C-1.3.2-Darwin.tar.gz
- tar xvf Eclipse-Paho-MQTT-C-1.3.2-Darwin.tar.gz -C ./paho.mqtt.c --strip-components=1
- export PAHO_HOME=$TRAVIS_BUILD_DIR/paho.mqtt.c
install:
- mkdir cmake && cd cmake && cmake ..
script:
- make install VERBOSE=1
before_deploy:
- tar -zcvf mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.tar.gz mqtt
deploy:
provider: releases
api_key: "$GITHUB_APIKEY"
file: mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.tar.gz
on:
tags: true
skip_cleanup: 'true'
script:
- if [[ $TESTS == "True" && "x$OD" != "x" && "x$QLIC_KC" != "x" ]]; then
q test.q tests/ -q;
fi
- if [[ $TRAVIS_OS_NAME == "windows" && $BUILD == "True" ]]; then
7z a -tzip -r $FILE_NAME ./cmake/$FILE_ROOT/*;
elif [[ $BUILD == "True" && ( $TRAVIS_OS_NAME == "linux" || $TRAVIS_OS_NAME == "osx" ) ]]; then
tar -zcvf $FILE_NAME -C cmake/$FILE_ROOT .;
elif [[ $TRAVIS_OS_NAME == "windows" ]]; then
7z a -tzip $FILE_NAME README.md install.bat LICENSE q examples;
elif [[ $TRAVIS_OS_NAME == "linux" || $TRAVIS_OS_NAME == "osx" ]]; then
tar -zcvf $FILE_NAME README.md install.sh LICENSE q examples;
fi

# WINDOWS (VISUAL STUDIO 2017) BUILD
- stage: build Release
if: branch != coverity_scan
name: "Windows MVS 2017 Build Release"
os: windows
before_install:
- mkdir paho.mqtt.c
- wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/eclipse-paho-mqtt-c-win64-1.3.2.zip
- 7z x -opaho.mqtt.c eclipse-paho-mqtt-c-win64-1.3.2.zip
- export PAHO_HOME=$TRAVIS_BUILD_DIR/paho.mqtt.c
install:
- mkdir cmake && cd cmake && cmake -G "Visual Studio 15 2017 Win64" ..
script:
- export MSBUILD_PATH="/c/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/MSBuild/15.0/Bin/"
- export PATH=$PATH:$MSBUILD_PATH
- MSBuild.exe INSTALL.vcxproj //m //nologo //verbosity:normal //p:Configuration=Release //p:Platform=x64
before_deploy:
- 7z a -r mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.zip mqtt/*
deploy:
provider: releases
api_key: "$GITHUB_APIKEY"
file: mqtt-${TRAVIS_OS_NAME}-${TRAVIS_TAG}.zip
on:
tags: true
skip_cleanup: 'true'

deploy:
provider: releases
api_key: "$GITHUB_APIKEY"
file: "$FILE_NAME"
on:
tags: true
condition: $TRAVIS_OS_NAME = windows || $TRAVIS_OS_NAME = osx || ($TRAVIS_DIST = trusty && $TRAVIS_OS_NAME = linux)
skip_cleanup: 'true'
46 changes: 35 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
if(NOT DEFINED ENV{BUILD_HOME})
message(FATAL_ERROR "BUILD_HOME must be set to the location of your installed C api repository")
endif()

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE MinSizeRel)
endif()

cmake_minimum_required(VERSION 2.8)
project(mqtt C)

set (CMAKE_BUILD_TYPE Release)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DKXVER=3")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -DKXVER=3")

Expand All @@ -11,38 +18,40 @@ set_source_files_properties(${SRC_FILES} PROPERTIES LANGUAGE C)

message(STATUS "Generator : ${CMAKE_GENERATOR}")
message(STATUS "Build Tool : ${CMAKE_BUILD_TOOL}")
message(STATUS "Paho MQTT API : $ENV{PAHO_HOME}")
message(STATUS "C API : $ENV{BUILD_HOME}")

include_directories (
$ENV{PAHO_HOME}/include
$ENV{BUILD_HOME}/include
${CMAKE_BINARY_DIR} # For 'k.h', downloaded below
)

find_library(MQTT3A_LIBRARY
NAMES paho-mqtt3a
HINTS "$ENV{PAHO_HOME}/lib/"
HINTS "$ENV{BUILD_HOME}/lib/"
)
find_library(MQTT3AS_LIBRARY
NAMES paho-mqtt3as
HINTS "$ENV{PAHO_HOME}/lib/"
HINTS "$ENV{BUILD_HOME}/lib/"
)
find_library(MQTT3C_LIBRARY
NAMES paho-mqtt3c
HINTS "$ENV{PAHO_HOME}/lib/"
HINTS "$ENV{BUILD_HOME}/lib/"
)
find_library(MQTT3CS_LIBRARY
NAMES paho-mqtt3cs
HINTS "$ENV{PAHO_HOME}/lib/"
HINTS "$ENV{BUILD_HOME}/lib/"
)

file(DOWNLOAD "https://github.com/KxSystems/kdb/raw/master/c/c/k.h" "${CMAKE_BINARY_DIR}/k.h" )

if (MSVC)
set(INSTALL_SCRIPT "install.bat")
file(DOWNLOAD "https://github.com/KxSystems/kdb/raw/master/w64/q.lib" "${CMAKE_BINARY_DIR}/q.lib" )
set(LINK_LIBS "${CMAKE_BINARY_DIR}/q.lib")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /D WIN32_LEAN_AND_MEAN /D _CRT_SECURE_NO_WARNINGS /D _CRT_NONSTDC_NO_DEPRECATE /D _WINSOCK_DEPRECATED_NO_WARNINGS")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /D WIN32_LEAN_AND_MEAN /D _CRT_SECURE_NO_WARNINGS /D _CRT_NONSTDC_NO_DEPRECATE /D _WINSOCK_DEPRECATED_NO_WARNINGS")
else()
set(INSTALL_SCRIPT "install.sh")
set(LINK_LIBS "")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-strict-aliasing")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing")
Expand All @@ -53,12 +62,27 @@ add_library (${MY_LIBRARY_NAME} SHARED ${SRC_FILES})
IF(APPLE)
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES SUFFIX .so)
set(OSFLAG m)
elseif(WIN32)
set(OSFLAG w)
else()
set(OSFLAG l)
endif()

target_link_libraries(${MY_LIBRARY_NAME} ${MQTT3A_LIBRARY} ${MQTT3AS_LIBRARY} ${MQTT3C_LIBRARY} ${MQTT3CS_LIBRARY} ${LINK_LIBS})
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES PREFIX "")

install(FILES README.md LICENSE install.sh install.bat DESTINATION ${PROJECT_BINARY_DIR}/mqtt/)
install(DIRECTORY examples DESTINATION ${PROJECT_BINARY_DIR}/mqtt)
install(DIRECTORY q DESTINATION ${PROJECT_BINARY_DIR}/mqtt)
install(TARGETS ${MY_LIBRARY_NAME} DESTINATION ${PROJECT_BINARY_DIR}/mqtt/lib OPTIONAL)
# Check if 32-bit/64-bit machine
set(BITNESS 32)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(BITNESS 64)
endif()

# Minimum build/install move binary and q-script to $QHOME & $QHOME/<QARCH>
install(TARGETS ${MY_LIBRARY_NAME} DESTINATION "$ENV{QHOME}/${OSFLAG}${BITNESS}/" CONFIGURATIONS MinSizeRel Release)
install(DIRECTORY "q/" DESTINATION "$ENV{QHOME}" CONFIGURATIONS MinSizeRel Release FILES_MATCHING PATTERN "*.q")

install(FILES README.md LICENSE ${INSTALL_SCRIPT} DESTINATION ${PROJECT_BINARY_DIR}/mqtt/ CONFIGURATIONS Release)
install(DIRECTORY examples DESTINATION ${PROJECT_BINARY_DIR}/mqtt CONFIGURATIONS Release)
install(DIRECTORY q DESTINATION ${PROJECT_BINARY_DIR}/mqtt CONFIGURATIONS Release)
install(TARGETS ${MY_LIBRARY_NAME} DESTINATION ${PROJECT_BINARY_DIR}/mqtt/lib CONFIGURATIONS Release)
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,26 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
Linux, MacOS and Windows users should complete the following steps

1. Download the latest release of the `paho.mqtt.c` C api for your system architecture, available [here](https://github.com/eclipse/paho.mqtt.c/releases).
2. Unzip this release to a location appropriate for your system.
3. Set an environment variable `$PAHO_HOME` / `%PAHO_HOME%` pointing to the location of the installed and unzipped release.
2. Unzip this release and move to a location appropriate for your system.
3. Set an environment variable `$BUILD_HOME` / `%BUILD_HOME%` pointing to the location of the installed and unzipped release.
4. Make the paho.mqtt.c api available to kdb.

For Linux and MacOS, add the location of the 'lib' directory to `LD_LIBRARY_PATH`/`DYLD_LIBRARY_PATH` as appropriate
```
## Linux
export LD_LIBRARY_PATH=$PAHO_HOME/lib/:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=$BUILD_HOME/lib/:$LD_LIBRARY_PATH
## MacOS
export DYLD_LIBRARY_PATH=$PAHO_HOME/lib/:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH=$BUILD_HOME/lib/:$DYLD_LIBRARY_PATH
```
For Windows, create links to the paho dll's in the `%QHOME%\w64` directory.
e.g.
```
cd %QHOME%\w64
MKLINK paho-mqtt3a.dll %PAHO_HOME%\lib\paho-mqtt3a.dll
MKLINK paho-mqtt3as.dll %PAHO_HOME%\lib\paho-mqtt3as.dll
MKLINK paho-mqtt3c.dll %PAHO_HOME%\lib\paho-mqtt3c.dll
MKLINK paho-mqtt3cs.dll %PAHO_HOME%\lib\paho-mqtt3cs.dll
MKLINK paho-mqtt3a.dll %BUILD_HOME%\lib\paho-mqtt3a.dll
MKLINK paho-mqtt3as.dll %BUILD_HOME%\lib\paho-mqtt3as.dll
MKLINK paho-mqtt3c.dll %BUILD_HOME%\lib\paho-mqtt3c.dll
MKLINK paho-mqtt3cs.dll %BUILD_HOME%\lib\paho-mqtt3cs.dll
```

#### ARM 32 build
Expand All @@ -77,7 +77,7 @@ install.bat

In order to successfully build and install this interface from source, the following environment variables must be set

1. `PAHO_HOME` = Location of a paho mqtt C api release
1. `BUILD_HOME` = Location of a paho mqtt C api release
2. `QHOME` = Q installation directory (directory containing `q.k`)

#### Linux/MacOS/ARM 32-bit
Expand Down Expand Up @@ -144,7 +144,7 @@ cd mqtt && install.bat

A sample docker file is provided in the `docker_linux` directory to create a CentOS 7 environment (including downloading the `paho.mqtt.c` 64 bit Linux release) before building and installing the kdb+ `mqtt` interface.

The `PAHO_HOME` and `QHOME` directories are specified at the top of `mqtt_build.bat`, which sets up the environment specified in `Dockerfile.build` and invokes `mqtt_build.sh` to build the library.
The `BUILD_HOME` and `QHOME` directories are specified at the top of `mqtt_build.bat`, which sets up the environment specified in `Dockerfile.build` and invokes `mqtt_build.sh` to build the library.

## Documentation

Expand Down
2 changes: 1 addition & 1 deletion docker_linux/Dockerfile.build
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ENV PATH /q/l64:$PATH
ENV LD_LIBRARY_PATH /usr/local/lib:$LD_LIBRARY_PATH

RUN cd /source && wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz && tar xvf Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz -C ./paho.mqtt.c --strip-components=1
ENV PAHO_HOME /source/paho.mqtt.c
ENV BUILD_HOME /source/paho.mqtt.c

COPY mqtt_build.sh /source
RUN /source/mqtt_build.sh
Expand Down
Empty file modified install.sh
100644 → 100755
Empty file.
16 changes: 16 additions & 0 deletions travis_setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

mkdir cbuild

if [ "$TRAVIS_OS_NAME" == "osx" ]; then
wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/Eclipse-Paho-MQTT-C-1.3.2-Darwin.tar.gz
tar xvf Eclipse-Paho-MQTT-C-1.3.2-Darwin.tar.gz -C ./cbuild --strip-components=1
elif [ "$TRAVIS_OS_NAME" == "linux" ]; then
wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz
tar xvf Eclipse-Paho-MQTT-C-1.3.2-Linux.tar.gz -C ./cbuild --strip-components=1
elif [ "$TRAVIS_OS_NAME" == "windows" ]; then
wget https://github.com/eclipse/paho.mqtt.c/releases/download/v1.3.2/eclipse-paho-mqtt-c-win64-1.3.2.zip
7z x -ocbuild eclipse-paho-mqtt-c-win64-1.3.2.zip
else
echo "$TRAVIS_OS_NAME is currently not supported"
fi

0 comments on commit edb1c0b

Please sign in to comment.