How to configure native builds differently on various host systems?


(Sean Fridman) #1

Is there any Gradle API to query the host operating system name? I’m trying to configure a native-binary build differently in different host environments (like “make”, where you often specify different CFLAGS for each supported build environment: one for “linux”, one for “darwin”, etc). Right now I’m using a apache.commons.lang class to query it and configure a SharedLibraryBinary in an if else block. Doesn’t seem like the most Gradle-y way of doing it… And if there is no Gradle API, still, is there a better way of doing what I’m trying to do?


(rtayek) #2

just use System.getproperty directly: http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html. relavent keys:

“os.arch” Operating system architecture “os.name” Operating system name “os.version” Operating system version


(Sean Fridman) #3

Sorry, I should have mentioned that “os.name” is a bit raw and requires additional parsing. It works sure! Just ever so slightly inconvenient. Plus, that doesn’t solve the nasty if/else block. I was wondering whether Gradle might have a slightly more integrated/elegant solution. I figure this is a fairly common use case for native builds?


(Sean Fridman) #4

Sorry, I should have mentioned that “os.name” is a bit raw and requires additional parsing. It works sure! Just ever so slightly inconvenient. Plus, that doesn’t solve the nasty if/else block. I was wondering whether Gradle might have a slightly more integrated/elegant solution. I figure this is a fairly common use case for native builds?


(rtayek) #5

i don’t know of anything more. maybe these guys http://lopica.sourceforge.net/os.html have some code to parse them.