最近用QTK开发一个下载(下载到开发板)工具,同时用到了Makefile/cmake和node-gyp,而且都要针对不同平台做不同的处理。这里做个记录,以备以后有需要时查阅。
Makefile
在Makefile中,可以用OS变量判断当前系统是否是Windows,然后用uname来判断当前系统是MacOS还是其它系统。
ifeq ($(OS),Windows_NT) PLATFORM="Windows"else ifeq ($(shell uname),Darwin) PLATFORM="MacOS" else PLATFORM="Unix-Like" endifendifall: @echo $(PLATFORM)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
cmake
在cmake中,可以通过APPLE变量判断当前系统是否是MacOS,通过UNIX变量判断当前系统是否是UNIX,其它则认为是Windows。
if(APPLE)//APPLEelseif(UNIX)//UNIXelse()//Windowsendif()
- 1
- 2
- 3
- 4
- 5
- 6
- 7
node-gyp
在binding.gyp中,可以在conditions添加不同平台的处理。
'conditions': [ ['OS=="mac"', { 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES' }, "sources": ["native/serial/src/impl/list_ports/list_ports_osx.cc","native/serial/src/impl/unix.cc"] }, 'OS=="win"', { "sources": ["native/serial/src/impl/list_ports/list_ports_win.cc","native/serial/src/impl/win.cc"], 'libraries': [ '-lsetupapi.lib', '-lws2_32.lib' ] }] ]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow