当前位置: 移动技术网 > IT编程>开发语言>JavaScript > Makefile/cmake/node-gyp中区分判断不同平台的方法

Makefile/cmake/node-gyp中区分判断不同平台的方法

2019年01月04日  | 移动技术网IT编程  | 我要评论

最近用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"
 endif
endif
all:
  @echo $(platform)

cmake

在cmake中,可以通过apple变量判断当前系统是否是macos,通过unix变量判断当前系统是否是unix,其它则认为是windows。

if(apple)
//apple
elseif(unix)
//unix
else()
//windows
endif()

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'
    ]
    }]
   ]

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,谢谢大家对移动技术网的支持。如果你想了解更多相关内容请查看下面相关链接

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网