Skip to content

Instantly share code, notes, and snippets.

@ldhertert
Last active October 15, 2015 19:47
Show Gist options
  • Save ldhertert/6a5597a93013da06044a to your computer and use it in GitHub Desktop.
Save ldhertert/6a5597a93013da06044a to your computer and use it in GitHub Desktop.
Windows Open-ZWave compilation for node-openzwave-shared
#This script will download a modified version of open-zwave (added support for visual studio 2013 and x64), build them and copy required files to ./libs/open-zwave
#Requirements
### cwd is root of your project
### You have visual studio 2013 installed with C++ build tools
### msbuild is in your path
$ErrorActionPreference = "Stop"
Push-Location
if ((Test-Path .\lib) -eq $false) {
mkdir .\lib
}
if (Test-Path .\lib\open-zwave) {
rm -Recurse -Force .\lib\open-zwave
}
mkdir .\lib\open-zwave
cd .\lib\open-zwave
mkdir .\temp
Invoke-WebRequest "https://github.com/ldhertert/open-zwave/archive/x64-support.zip" -OutFile ".\temp\open-zwave.zip"
mkdir .\temp\open-zwave
Expand-Archive -Path .\temp\open-zwave.zip -DestinationPath .\temp\open-zwave
MSBuild.exe .\temp\open-zwave\open-zwave-x64-support\cpp\build\windows\vs2013\OpenZWave.sln /p:Configuration="Release" /nologo /verbosity:quiet /p:Platform=Win32
MSBuild.exe .\temp\open-zwave\open-zwave-x64-support\cpp\build\windows\vs2013\OpenZWave.sln /p:Configuration="Release" /nologo /verbosity:quiet /p:Platform=x64
mkdir .\include
cp .\temp\open-zwave\open-zwave-x64-support\cpp\build\windows\vs2013\Release\OpenZWave.lib .\OpenZWave.Win32.lib
cp .\temp\open-zwave\open-zwave-x64-support\cpp\build\windows\vs2013\x64\Release\OpenZWave.lib .\OpenZWave.x64.lib
#copy all header files recursively
robocopy .\temp\open-zwave\open-zwave-x64-support\cpp\src .\include *.h /s
cp -Recurse .\temp\open-zwave\open-zwave-x64-support\config .\config
rm -Recurse -Force .\temp
Pop-Location
//This file will download the most recent version of open zwave, build it, copy it to
//~\AppData\Local\OpenZwave, and set the environment variable OZW_HOME
//USAGE: node install-ozw-windows.js [node-gyp-args]
//One line powershell install: $x=[System.IO.Path]::GetTempFileName(); (new-object net.webclient).DownloadFile("https://gist.githubusercontent.com/ldhertert/6a5597a93013da06044a/raw/install-ozw-windows.js",$x); node $x;
var fs = require('fs');
var ChildProcess = require('child_process');
var path = require('path');
var originalPath = process.cwd();
var tempPath = path.resolve(require('os').tmpDir() + 'ozwinstall/' + Math.random().toString(36).substring(7));
var installPath = path.resolve(process.env.HOMEPATH + '/AppData/Local/OpenZWave/');
var ozwSourceUrl = "https://github.com/OpenZWave/open-zwave/archive/master.zip";
var gypOptions = [];
fs.mkdirSync(tempPath);
process.chdir(tempPath);
console.log('Installing dependencies to ' + tempPath);
ChildProcess.execSync('npm install request unzip node-gyp wrench');
var request = require(tempPath + '/node_modules/request');
var unzip = require(tempPath + '/node_modules/unzip');
var gyp = require(tempPath + '/node_modules/node-gyp')();
var wrench = require(tempPath + '/node_modules/wrench');
var ozwGyp = {
"targets": [
{
"target_name": "openzwave",
"type": "static_library",
"sources": [
"cpp/tinyxml/tinystr.cpp",
"cpp/tinyxml/tinyxml.cpp",
"cpp/tinyxml/tinyxmlerror.cpp",
"cpp/tinyxml/tinyxmlparser.cpp",
"cpp/src/aes/aes_modes.c",
"cpp/src/aes/aescrypt.c",
"cpp/src/aes/aeskey.c",
"cpp/src/aes/aestab.c",
"cpp/src/command_classes/Alarm.cpp",
"cpp/src/command_classes/ApplicationStatus.cpp",
"cpp/src/command_classes/Association.cpp",
"cpp/src/command_classes/AssociationCommandConfiguration.cpp",
"cpp/src/command_classes/Basic.cpp",
"cpp/src/command_classes/BasicWindowCovering.cpp",
"cpp/src/command_classes/Battery.cpp",
"cpp/src/command_classes/CRC16Encap.cpp",
"cpp/src/command_classes/ClimateControlSchedule.cpp",
"cpp/src/command_classes/CentralScene.cpp",
"cpp/src/command_classes/Clock.cpp",
"cpp/src/command_classes/Color.cpp",
"cpp/src/command_classes/CommandClass.cpp",
"cpp/src/command_classes/CommandClasses.cpp",
"cpp/src/command_classes/Configuration.cpp",
"cpp/src/command_classes/ControllerReplication.cpp",
"cpp/src/command_classes/DeviceResetLocally.cpp",
"cpp/src/command_classes/DoorLock.cpp",
"cpp/src/command_classes/DoorLockLogging.cpp",
"cpp/src/command_classes/EnergyProduction.cpp",
"cpp/src/command_classes/Hail.cpp",
"cpp/src/command_classes/Indicator.cpp",
"cpp/src/command_classes/Language.cpp",
"cpp/src/command_classes/Lock.cpp",
"cpp/src/command_classes/ManufacturerSpecific.cpp",
"cpp/src/command_classes/Meter.cpp",
"cpp/src/command_classes/MeterPulse.cpp",
"cpp/src/command_classes/MultiCmd.cpp",
"cpp/src/command_classes/MultiInstance.cpp",
"cpp/src/command_classes/MultiInstanceAssociation.cpp",
"cpp/src/command_classes/NoOperation.cpp",
"cpp/src/command_classes/NodeNaming.cpp",
"cpp/src/command_classes/Powerlevel.cpp",
"cpp/src/command_classes/Proprietary.cpp",
"cpp/src/command_classes/Protection.cpp",
"cpp/src/command_classes/SceneActivation.cpp",
"cpp/src/command_classes/Security.cpp",
"cpp/src/command_classes/SensorAlarm.cpp",
"cpp/src/command_classes/SensorBinary.cpp",
"cpp/src/command_classes/SensorMultilevel.cpp",
"cpp/src/command_classes/SwitchAll.cpp",
"cpp/src/command_classes/SwitchBinary.cpp",
"cpp/src/command_classes/SwitchMultilevel.cpp",
"cpp/src/command_classes/SwitchToggleBinary.cpp",
"cpp/src/command_classes/SwitchToggleMultilevel.cpp",
"cpp/src/command_classes/ThermostatFanMode.cpp",
"cpp/src/command_classes/ThermostatFanState.cpp",
"cpp/src/command_classes/ThermostatMode.cpp",
"cpp/src/command_classes/ThermostatOperatingState.cpp",
"cpp/src/command_classes/ThermostatSetpoint.cpp",
"cpp/src/command_classes/TimeParameters.cpp",
"cpp/src/command_classes/UserCode.cpp",
"cpp/src/command_classes/Version.cpp",
"cpp/src/command_classes/WakeUp.cpp",
"cpp/src/command_classes/ZWavePlusInfo.cpp",
"cpp/src/value_classes/Value.cpp",
"cpp/src/value_classes/ValueBool.cpp",
"cpp/src/value_classes/ValueButton.cpp",
"cpp/src/value_classes/ValueByte.cpp",
"cpp/src/value_classes/ValueDecimal.cpp",
"cpp/src/value_classes/ValueInt.cpp",
"cpp/src/value_classes/ValueList.cpp",
"cpp/src/value_classes/ValueRaw.cpp",
"cpp/src/value_classes/ValueSchedule.cpp",
"cpp/src/value_classes/ValueShort.cpp",
"cpp/src/value_classes/ValueStore.cpp",
"cpp/src/value_classes/ValueString.cpp",
"cpp/src/platform/Controller.cpp",
"cpp/src/platform/Event.cpp",
"cpp/src/platform/FileOps.cpp",
"cpp/src/platform/HidController.cpp",
"cpp/src/platform/Log.cpp",
"cpp/src/platform/Mutex.cpp",
"cpp/src/platform/SerialController.cpp",
"cpp/src/platform/Stream.cpp",
"cpp/src/platform/Thread.cpp",
"cpp/src/platform/TimeStamp.cpp",
"cpp/src/platform/Wait.cpp",
"cpp/src/Driver.cpp",
"cpp/src/Group.cpp",
"cpp/src/Manager.cpp",
"cpp/src/Msg.cpp",
"cpp/src/Node.cpp",
"cpp/src/Notification.cpp",
"cpp/src/Options.cpp",
"cpp/src/Scene.cpp",
"cpp/src/Utils.cpp",
"cpp/src/ZWSecurity.cpp"
],
"include_dirs": [
"cpp/hidapi/hidapi",
"cpp/src",
"cpp/src/command_classes",
"cpp/src/platform",
"cpp/src/value_classes",
"cpp/tinyxml"
],
"configurations": {
"Release": {
"cflags": [
"-Wno-ignored-qualifiers",
"-Wno-tautological-undefined-compare",
"-Wno-unknown-pragmas"
],
"xcode_settings": {
"OTHER_CFLAGS": [
"-Wno-ignored-qualifiers",
"-Wno-tautological-undefined-compare",
"-Wno-unknown-pragmas"
]
},
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1
}
},
}
},
"conditions": [
['OS=="linux"', {
"include_dirs": [ "cpp/src/platform/unix" ],
"sources": [
"cpp/hidapi/linux/hid.c",
"cpp/src/platform/unix/EventImpl.cpp",
"cpp/src/platform/unix/FileOpsImpl.cpp",
"cpp/src/platform/unix/LogImpl.cpp",
"cpp/src/platform/unix/MutexImpl.cpp",
"cpp/src/platform/unix/SerialControllerImpl.cpp",
"cpp/src/platform/unix/ThreadImpl.cpp",
"cpp/src/platform/unix/TimeStampImpl.cpp",
"cpp/src/platform/unix/WaitImpl.cpp"
]
}],
['OS=="mac"', {
"include_dirs": [ "cpp/src/platform/unix" ],
"sources": [
"cpp/hidapi/mac/hid.c",
"cpp/src/platform/unix/EventImpl.cpp",
"cpp/src/platform/unix/FileOpsImpl.cpp",
"cpp/src/platform/unix/LogImpl.cpp",
"cpp/src/platform/unix/MutexImpl.cpp",
"cpp/src/platform/unix/SerialControllerImpl.cpp",
"cpp/src/platform/unix/ThreadImpl.cpp",
"cpp/src/platform/unix/TimeStampImpl.cpp",
"cpp/src/platform/unix/WaitImpl.cpp"
],
"defines": [
"DARWIN"
]
}],
['OS=="win"', {
"include_dirs": [ "cpp/src/platform/windows" ],
"sources": [
"cpp/build/windows/winversion.cpp",
"cpp/hidapi/windows/hid.cpp",
"cpp/src/platform/windows/EventImpl.cpp",
"cpp/src/platform/windows/FileOpsImpl.cpp",
"cpp/src/platform/windows/LogImpl.cpp",
"cpp/src/platform/windows/MutexImpl.cpp",
"cpp/src/platform/windows/SerialControllerImpl.cpp",
"cpp/src/platform/windows/ThreadImpl.cpp",
"cpp/src/platform/windows/TimeStampImpl.cpp",
"cpp/src/platform/windows/WaitImpl.cpp"
]
}],
]
}
]
};
function init() {
console.log('Temp Path:', tempPath);
console.log('Install Path:', installPath);
wrench.rmdirSyncRecursive(installPath, true);
wrench.mkdirSyncRecursive(installPath);
}
function download(url, dest, cb) {
//doesn't handle error response codes
request({uri: url})
.pipe(fs.createWriteStream(dest))
.on('close', cb)
.on('error', cb);
}
function build(gypArgs, cb) {
try {
fs.unlinkSync('./cpp/build/windows/winversion.cpp');
} catch (e) { }
ChildProcess.execFile('GIT-VS-VERSION-GEN.bat',
['../../', 'winversion.cpp'],
{ cwd: './cpp/build/windows' },
function (error, stdout, stderr) {
if (error) {
console.log(error.stack);
console.log('Error code: '+error.code);
console.log('Signal received: '+error.signal);
}
});
var args = ['node','.'];
if (gypArgs) {
args = args.concat(gypArgs);
}
gyp.parseArgv(args);
gyp.commands.clean([], function(err) {
if (err) return cb(err);
gyp.commands.configure([], function(err) {
if (err) return cb(err);
gyp.commands.build([], cb);
});
});
}
function copyFiles() {
wrench.copyDirSyncRecursive(tempPath + '/ozw/open-zwave-master/config', installPath + '/config');
wrench.copyDirSyncRecursive(tempPath + '/ozw/open-zwave-master/cpp/src', installPath + '/include', { filter: /^.*\.(?!h)[^.]+$/ });
wrench.copyDirSyncRecursive(tempPath + '/ozw/open-zwave-master/build/Release', installPath + '/bin');
}
function handleError(err) {
throw err;
}
module.exports = function(opts) {
gypOptions = opts.gyp || gypOptions;
init();
console.log('Downloading open zwave source.');
download(ozwSourceUrl, tempPath + "/ozw.zip", function(err) {
if (err) { return handleError(err); }
console.log('Extracting open zwave source.');
fs.createReadStream( tempPath + "/ozw.zip")
.pipe(unzip.Extract({ path: tempPath + '/ozw' }))
.on('close', function() {
fs.writeFile(tempPath + '/ozw/open-zwave-master/binding.gyp', JSON.stringify(ozwGyp, null, 4), function(err) {
if(err) handleError;
console.log('Building open zwave');
process.chdir(tempPath + "/ozw/open-zwave-master");
build(gypOptions, function(err) {
if (err) handleError(err);
process.chdir(originalPath);
copyFiles();
//set environment variable
ChildProcess.exec('SETX OZW_HOME "' + installPath + '"',function(error, stdout, stderr) {
// command output is in stdout
});
});
});
})
.on('error', handleError);
});
}
if (require.main === module) {
module.exports({ gyp: process.argv.slice(2) });
}
#i was able to get this to work against the unmodified openzwave repo
#maybe use this instead of visual studio projects, so it uses the same build style/settings/architecture as node-openzwave-shared
{
"targets": [
{
"target_name": "openzwave",
"type": "static_library",
"sources": [
"ozw/cpp/tinyxml/tinystr.cpp",
"ozw/cpp/tinyxml/tinyxml.cpp",
"ozw/cpp/tinyxml/tinyxmlerror.cpp",
"ozw/cpp/tinyxml/tinyxmlparser.cpp",
"ozw/cpp/src/aes/aes_modes.c",
"ozw/cpp/src/aes/aescrypt.c",
"ozw/cpp/src/aes/aeskey.c",
"ozw/cpp/src/aes/aestab.c",
"ozw/cpp/src/command_classes/Alarm.cpp",
"ozw/cpp/src/command_classes/ApplicationStatus.cpp",
"ozw/cpp/src/command_classes/Association.cpp",
"ozw/cpp/src/command_classes/AssociationCommandConfiguration.cpp",
"ozw/cpp/src/command_classes/Basic.cpp",
"ozw/cpp/src/command_classes/BasicWindowCovering.cpp",
"ozw/cpp/src/command_classes/Battery.cpp",
"ozw/cpp/src/command_classes/CRC16Encap.cpp",
"ozw/cpp/src/command_classes/ClimateControlSchedule.cpp",
"ozw/cpp/src/command_classes/CentralScene.cpp",
"ozw/cpp/src/command_classes/Clock.cpp",
"ozw/cpp/src/command_classes/Color.cpp",
"ozw/cpp/src/command_classes/CommandClass.cpp",
"ozw/cpp/src/command_classes/CommandClasses.cpp",
"ozw/cpp/src/command_classes/Configuration.cpp",
"ozw/cpp/src/command_classes/ControllerReplication.cpp",
"ozw/cpp/src/command_classes/DeviceResetLocally.cpp",
"ozw/cpp/src/command_classes/DoorLock.cpp",
"ozw/cpp/src/command_classes/DoorLockLogging.cpp",
"ozw/cpp/src/command_classes/EnergyProduction.cpp",
"ozw/cpp/src/command_classes/Hail.cpp",
"ozw/cpp/src/command_classes/Indicator.cpp",
"ozw/cpp/src/command_classes/Language.cpp",
"ozw/cpp/src/command_classes/Lock.cpp",
"ozw/cpp/src/command_classes/ManufacturerSpecific.cpp",
"ozw/cpp/src/command_classes/Meter.cpp",
"ozw/cpp/src/command_classes/MeterPulse.cpp",
"ozw/cpp/src/command_classes/MultiCmd.cpp",
"ozw/cpp/src/command_classes/MultiInstance.cpp",
"ozw/cpp/src/command_classes/MultiInstanceAssociation.cpp",
"ozw/cpp/src/command_classes/NoOperation.cpp",
"ozw/cpp/src/command_classes/NodeNaming.cpp",
"ozw/cpp/src/command_classes/Powerlevel.cpp",
"ozw/cpp/src/command_classes/Proprietary.cpp",
"ozw/cpp/src/command_classes/Protection.cpp",
"ozw/cpp/src/command_classes/SceneActivation.cpp",
"ozw/cpp/src/command_classes/Security.cpp",
"ozw/cpp/src/command_classes/SensorAlarm.cpp",
"ozw/cpp/src/command_classes/SensorBinary.cpp",
"ozw/cpp/src/command_classes/SensorMultilevel.cpp",
"ozw/cpp/src/command_classes/SwitchAll.cpp",
"ozw/cpp/src/command_classes/SwitchBinary.cpp",
"ozw/cpp/src/command_classes/SwitchMultilevel.cpp",
"ozw/cpp/src/command_classes/SwitchToggleBinary.cpp",
"ozw/cpp/src/command_classes/SwitchToggleMultilevel.cpp",
"ozw/cpp/src/command_classes/ThermostatFanMode.cpp",
"ozw/cpp/src/command_classes/ThermostatFanState.cpp",
"ozw/cpp/src/command_classes/ThermostatMode.cpp",
"ozw/cpp/src/command_classes/ThermostatOperatingState.cpp",
"ozw/cpp/src/command_classes/ThermostatSetpoint.cpp",
"ozw/cpp/src/command_classes/TimeParameters.cpp",
"ozw/cpp/src/command_classes/UserCode.cpp",
"ozw/cpp/src/command_classes/Version.cpp",
"ozw/cpp/src/command_classes/WakeUp.cpp",
"ozw/cpp/src/command_classes/ZWavePlusInfo.cpp",
"ozw/cpp/src/value_classes/Value.cpp",
"ozw/cpp/src/value_classes/ValueBool.cpp",
"ozw/cpp/src/value_classes/ValueButton.cpp",
"ozw/cpp/src/value_classes/ValueByte.cpp",
"ozw/cpp/src/value_classes/ValueDecimal.cpp",
"ozw/cpp/src/value_classes/ValueInt.cpp",
"ozw/cpp/src/value_classes/ValueList.cpp",
"ozw/cpp/src/value_classes/ValueRaw.cpp",
"ozw/cpp/src/value_classes/ValueSchedule.cpp",
"ozw/cpp/src/value_classes/ValueShort.cpp",
"ozw/cpp/src/value_classes/ValueStore.cpp",
"ozw/cpp/src/value_classes/ValueString.cpp",
"ozw/cpp/src/platform/Controller.cpp",
"ozw/cpp/src/platform/Event.cpp",
"ozw/cpp/src/platform/FileOps.cpp",
"ozw/cpp/src/platform/HidController.cpp",
"ozw/cpp/src/platform/Log.cpp",
"ozw/cpp/src/platform/Mutex.cpp",
"ozw/cpp/src/platform/SerialController.cpp",
"ozw/cpp/src/platform/Stream.cpp",
"ozw/cpp/src/platform/Thread.cpp",
"ozw/cpp/src/platform/TimeStamp.cpp",
"ozw/cpp/src/platform/Wait.cpp",
"ozw/cpp/src/Driver.cpp",
"ozw/cpp/src/Group.cpp",
"ozw/cpp/src/Manager.cpp",
"ozw/cpp/src/Msg.cpp",
"ozw/cpp/src/Node.cpp",
"ozw/cpp/src/Notification.cpp",
"ozw/cpp/src/Options.cpp",
"ozw/cpp/src/Scene.cpp",
"ozw/cpp/src/Utils.cpp",
"ozw/cpp/src/vers.cpp",
"ozw/cpp/src/ZWSecurity.cpp"
],
"include_dirs": [
"ozw/cpp/hidapi/hidapi",
"ozw/cpp/src",
"ozw/cpp/src/command_classes",
"ozw/cpp/src/platform",
"ozw/cpp/src/value_classes",
"ozw/cpp/tinyxml"
],
"configurations": {
"Release": {
"cflags": [
"-Wno-ignored-qualifiers",
"-Wno-tautological-undefined-compare",
"-Wno-unknown-pragmas"
],
"xcode_settings": {
"OTHER_CFLAGS": [
"-Wno-ignored-qualifiers",
"-Wno-tautological-undefined-compare",
"-Wno-unknown-pragmas"
]
},
'msvs_settings': {
'VCCLCompilerTool': {
'ExceptionHandling': 1
}
},
}
},
"conditions": [
['OS=="linux"', {
"include_dirs": [ "ozw/cpp/src/platform/unix" ],
"sources": [
"ozw/cpp/hidapi/linux/hid.c",
"ozw/cpp/src/platform/unix/EventImpl.cpp",
"ozw/cpp/src/platform/unix/FileOpsImpl.cpp",
"ozw/cpp/src/platform/unix/LogImpl.cpp",
"ozw/cpp/src/platform/unix/MutexImpl.cpp",
"ozw/cpp/src/platform/unix/SerialControllerImpl.cpp",
"ozw/cpp/src/platform/unix/ThreadImpl.cpp",
"ozw/cpp/src/platform/unix/TimeStampImpl.cpp",
"ozw/cpp/src/platform/unix/WaitImpl.cpp"
]
}],
['OS=="mac"', {
"include_dirs": [ "ozw/cpp/src/platform/unix" ],
"sources": [
"ozw/cpp/hidapi/mac/hid.c",
"ozw/cpp/src/platform/unix/EventImpl.cpp",
"ozw/cpp/src/platform/unix/FileOpsImpl.cpp",
"ozw/cpp/src/platform/unix/LogImpl.cpp",
"ozw/cpp/src/platform/unix/MutexImpl.cpp",
"ozw/cpp/src/platform/unix/SerialControllerImpl.cpp",
"ozw/cpp/src/platform/unix/ThreadImpl.cpp",
"ozw/cpp/src/platform/unix/TimeStampImpl.cpp",
"ozw/cpp/src/platform/unix/WaitImpl.cpp"
],
"defines": [
"DARWIN"
]
}],
['OS=="win"', {
"include_dirs": [ "ozw/cpp/src/platform/windows" ],
"sources": [
"ozw/cpp/hidapi/windows/hid.cpp",
"ozw/cpp/src/platform/windows/EventImpl.cpp",
"ozw/cpp/src/platform/windows/FileOpsImpl.cpp",
"ozw/cpp/src/platform/windows/LogImpl.cpp",
"ozw/cpp/src/platform/windows/MutexImpl.cpp",
"ozw/cpp/src/platform/windows/SerialControllerImpl.cpp",
"ozw/cpp/src/platform/windows/ThreadImpl.cpp",
"ozw/cpp/src/platform/windows/TimeStampImpl.cpp",
"ozw/cpp/src/platform/windows/WaitImpl.cpp"
]
}],
]
}
]
}
@ldhertert
Copy link
Author

The only thing that is really necessary to change about the current version of open-zwave is to add an x64 platform target. The reason I had to add vs2013 support is because I don't have vs2010.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment