1+ <project default =" gather-props" >
2+ <!-- Properties for export to maven -->
3+ <target name =" gather-props" depends =" main-props,msvc-props,xcode-props,gcc-props,unset-props,test-props" >
4+ <propertyfile file =" ${ ant.properties.file } " >
5+ <entry key =" cmake.generator.nativelibdir" value =" ${ cmake.generator.nativelibdir } " />
6+ <entry key =" cmake.generator.arg" value =" ${ cmake.generator.arg } " />
7+ <entry key =" cmake.build.arg" value =" ${ cmake.build.arg } " />
8+ <entry key =" maven.nativelibdir.path" value =" ${ maven.nativelibdir.path } " />
9+ <entry key =" maven.assembly.id" value =" ${ maven.assembly.id } " />
10+ <entry key =" maven.test.skip" value =" ${ maven.test.skip } " />
11+ </propertyfile >
12+ </target >
13+
14+ <target name =" main-props" >
15+ <!-- Calculate the target system -->
16+ <!-- Note: Unlike maven, ant will preserve the value if already set -->
17+ <property name =" os.target.name" value =" ${ os.detected.name } " />
18+ <property name =" os.target.arch" value =" ${ os.detected.arch } " />
19+ <property name =" os.target.bitness" value =" ${ os.detected.bitness } " />
20+ <property name =" os.target.classifier" value =" ${ os.target.name } -${ os.target.arch } " />
21+
22+ <!-- Guess the compiler based on host os -->
23+ <!-- Windows: Assume MSVC -->
24+ <condition property =" use.msvc" value =" true" >
25+ <equals arg1=" ${ os.detected.name } " arg2=" windows" />
26+ </condition >
27+ <!-- MacOS: Assume XCode -->
28+ <condition property =" use.xcode" value =" true" >
29+ <equals arg1=" ${ os.detected.name } " arg2=" osx" />
30+ </condition >
31+ <!-- All others: Fallback on gcc -->
32+ <condition property =" use.gcc" value =" true" >
33+ <and >
34+ <not >
35+ <equals arg1=" ${ os.detected.name } " arg2=" osx" />
36+ </not >
37+ <not >
38+ <equals arg1=" ${ os.detected.name } " arg2=" windows" />
39+ </not >
40+ </and >
41+ </condition >
42+
43+ <!-- Translate "NATIVE_LIB_DIR" prefix portion:
44+ - os.target.arch: must compare to a valid os value from os-maven-plugin
45+ - os.target.nativelib.suffix: must be set to a valid directory os value from native-lib-loader plugin
46+ -->
47+ <property name =" nativelibdir.prefix" value =" ${ os.target.name } " />
48+
49+ <!-- Translate "NATIVE_LIB_DIR" suffix portion:
50+ - os.target.arch: must compare to a valid arch value from os-maven-plugin
51+ - os.target.nativelib.suffix: must be set to a valid directory suffix value from native-lib-loader plugin
52+ -->
53+ <!-- "x86_64" <=> "64" -->
54+ <condition property =" nativelibdir.suffix" value =" 64" >
55+ <equals arg1=" ${ os.target.arch } " arg2=" x86_64" />
56+ </condition >
57+ <!-- "x86_32" <=> "32" -->
58+ <condition property =" nativelibdir.suffix" value =" 32" >
59+ <equals arg1=" ${ os.target.arch } " arg2=" x86_32" />
60+ </condition >
61+ <!-- "aarch_64" <=> "arm64" -->
62+ <condition property =" nativelibdir.suffix" value =" arm64" >
63+ <equals arg1=" ${ os.target.arch } " arg2=" aarch_64" />
64+ </condition >
65+ <!-- "arm_32" <=> "arm" -->
66+ <condition property =" nativelibdir.suffix" value =" arm" >
67+ <equals arg1=" ${ os.target.arch } " arg2=" arm_32" />
68+ </condition >
69+ <!-- "ppc_64" <=> "ppc" -->
70+ <condition property =" nativelibdir.suffix" value =" ppc" >
71+ <equals arg1=" ${ os.target.arch } " arg2=" ppc_64" />
72+ </condition >
73+
74+ <!-- Set cmake property "NATIVE_LIB_DIR" -->
75+ <property name =" cmake.generator.nativelibdir" value =" -DNATIVE_LIB_DIR="${ nativelibdir.prefix } _${ nativelibdir.suffix } "" />
76+
77+ <!-- Handle toolchain files -->
78+ <!-- "linux" + "aarch_64" <=> "Aarch64.cmake" -->
79+ <condition property =" os.target.toolchain" value =" Aarch64" >
80+ <and >
81+ <equals arg1=" ${ os.target.arch } " arg2=" aarch_64" />
82+ <equals arg1=" ${ os.detected.name } " arg2=" linux" />
83+ </and >
84+ </condition >
85+ <!-- Others should be set in maven profile -->
86+ <condition property =" cmake.generator.arg" value =" -DCMAKE_TOOLCHAIN_FILE="${ ant.project.basedir } /toolchain/${ os.target.toolchain } .cmake"" >
87+ <isset property =" os.target.toolchain" />
88+ </condition >
89+
90+ <!-- Calculate the native output path for use with the "file" command later -->
91+ <property name =" maven.nativelibdir.path" value =" ${ cmake.generated.directory } /natives/${ nativelibdir.prefix } _${ nativelibdir.suffix } " />
92+
93+ <!-- Setup maven assembly id -->
94+ <property name =" maven.assembly.id" value =" ${ os.target.name } -${ os.target.arch } -${ os.target.bitness } " />
95+ </target >
96+
97+ <target name =" msvc-props" if =" use.msvc" >
98+ <!-- Translate arch to msvc format -->
99+ <!--
100+ - os.target.arch: must compare to a valid os value from os-maven-plugin
101+ - msvc.platform: must be set to a valid value from cmake "-A" option for visual studio platform selection
102+ -->
103+ <!-- "x86_64" <=> "x64" -->
104+ <condition property =" msvc.arch" value =" x64" >
105+ <equals arg1=" ${ os.target.arch } " arg2=" x86_64" />
106+ </condition >
107+ <!-- "x86_32" <=> "Win32" -->
108+ <condition property =" msvc.arch" value =" Win32" >
109+ <equals arg1=" ${ os.target.arch } " arg2=" x86_32" />
110+ </condition >
111+ <!-- "arm_32" <=> "ARM" -->
112+ <condition property =" msvc.arch" value =" ARM" >
113+ <equals arg1=" ${ os.target.arch } " arg2=" arm_32" />
114+ </condition >
115+ <!-- "aarch_64" <=> "ARM64" -->
116+ <condition property =" msvc.arch" value =" ARM64" >
117+ <equals arg1=" ${ os.target.arch } " arg2=" aarch_64" />
118+ </condition >
119+
120+ <!-- Set cmake property "CMAKE_GENERATOR_PLATFORM" -->
121+ <property name =" cmake.generator.arg" value =" -DCMAKE_GENERATOR_PLATFORM=${ msvc.arch } " />
122+
123+ <!-- Set cmake build to release -->
124+ <property name =" cmake.build.arg" value =" --config Release" />
125+ </target >
126+
127+ <target name =" xcode-props" if =" use.xcode" >
128+ <!-- Translate arch to xcode format -->
129+ <!--
130+ - os.target.arch: must compare to a valid os value from os-maven-plugin
131+ - xcode.arch: must be set to a valid value llvm/clang triple arch type
132+ -->
133+ <!-- x86_64 <=> x86_64 -->
134+ <condition property =" xcode.arch" value =" x86_64" >
135+ <equals arg1=" ${ os.target.arch } " arg2=" x86_64" />
136+ </condition >
137+ <!-- x86_32 <=> x86 -->
138+ <condition property =" xcode.arch" value =" x86" >
139+ <equals arg1=" ${ os.target.arch } " arg2=" x86_32" />
140+ </condition >
141+ <!-- aarch_64 <=> arm64 -->
142+ <condition property =" xcode.arch" value =" arm64" >
143+ <equals arg1=" ${ os.target.arch } " arg2=" aarch_64" />
144+ </condition >
145+ <!-- arm_32 <=> arm -->
146+ <condition property =" xcode.arch" value =" arm" >
147+ <equals arg1=" ${ os.target.arch } " arg2=" arm_32" />
148+ </condition >
149+
150+ <!-- Set cmake property "CMAKE_OSX_ARCHITECTURES" -->
151+ <property name =" cmake.generator.arg" value =" -DCMAKE_OSX_ARCHITECTURES=${ xcode.arch } " />
152+ </target >
153+
154+ <target name =" gcc-props" if =" use.gcc" >
155+ <!-- Translate arch to gcc format -->
156+ <!--
157+ - os.target.arch: must compare to a valid os value from os-maven-plugin
158+ - gcc.arch: one of "M32" or "M64", used to toggle -m32 and -m64 flags respectively
159+ -->
160+ <!-- x86_64 <=> M64 -->
161+ <condition property =" gcc.arch" value =" M64" >
162+ <equals arg1=" ${ os.target.arch } " arg2=" x86_64" />
163+ </condition >
164+ <!-- x86_32 <=> M32 -->
165+ <condition property =" gcc.arch" value =" M32" >
166+ <equals arg1=" ${ os.target.arch } " arg2=" x86_32" />
167+ </condition >
168+ <!-- Fallback to "IGNORE", which instruct cmake to skip this value -->
169+ <property description =" fallback value" name =" gcc.arch" value =" IGNORE" />
170+
171+ <!-- Set cmake property "CMAKE_OSX_ARCHITECTURES" -->
172+ <property name =" cmake.generator.arg" value =" -DFORCE_${ gcc.arch } =true" />
173+ </target >
174+
175+ <target name =" unset-props" >
176+ <!-- makes sure any unset cmake properties fallback to a blank value -->
177+ <!-- this works because ant properties cannot be changed once set-->
178+ <property description =" fallback value" name =" cmake.build.arg" value =" " />
179+ <property description =" fallback value" name =" cmake.generator.arg" value =" " />
180+ <property description =" fallback value" name =" cmake.generator.nativelibdir" value =" " />
181+ </target >
182+
183+ <target name =" test-props" >
184+ <!-- Calculate if tests will run -->
185+ <condition property =" maven.test.skip" value =" false" else =" true" >
186+ <!-- Honor existing flag if set -->
187+ <and >
188+ <not >
189+ <isset property =" maven.test.skip" />
190+ </not >
191+ <!-- Run tests if detected system matches target system -->
192+ <equals arg1=" ${ os.target.classifier } " arg2=" ${ os.detected.classifier } " />
193+ </and >
194+ </condition >
195+
196+ <!-- Summarize host/target -->
197+ <echo level =" info" >Tests will run only if the TARGET and HOST match:${ line.separator } ${ line.separator } </echo >
198+ <echo level =" info" >TARGET: ${ os.target.classifier } </echo >
199+ <echo level =" info" >DETECTED: ${ os.detected.classifier } </echo >
200+ <echo level =" info" />
201+
202+ <!-- Negate result for human readability -->
203+ <condition property =" maven.test.message" value =" Tests will NOT run" else =" Tests WILL run" >
204+ <equals arg1=" ${ maven.test.skip } " arg2=" true" />
205+ </condition >
206+ <echo level =" info" >===== ${ maven.test.message } =====</echo >
207+ <echo level =" info" />
208+ </target >
209+
210+ <target name =" show-file-info" >
211+ <!-- Show binary output file information -->
212+ <fileset id =" native.files" dir =" ${ maven.nativelibdir.path } " includes =" *" />
213+ <echo level =" info" >File information:</echo >
214+
215+ <!-- Calculate path to sh.exe (Windows only) -->
216+ <property environment =" env" />
217+ <property name =" git.sh.camel" value =" ${ env.ProgramFiles } \git\bin\sh.exe" />
218+ <condition property =" git.sh" value =" ${ env.PROGRAMFILES } \git\bin\sh.exe" else =" ${ git.sh.camel } " >
219+ <isset property =" env.PROGRAMFILES" />
220+ </condition >
221+
222+ <!-- Convert path to unix format -->
223+ <pathconvert targetos =" unix" property =" native.file.unix" refid =" native.files" />
224+
225+ <!-- Prepare command ("file" on unix, "sh.exe" on Windows)-->
226+ <condition property =" exec.command" value =" ${ git.sh } " else =" file" >
227+ <resourceexists >
228+ <file file =" ${ git.sh } " />
229+ </resourceexists >
230+ </condition >
231+
232+ <!-- Prepare argument line -->
233+ <condition property =" exec.argline" value =" -c "file '${ native.file.unix } '"" else =" '${ native.file.unix } '" >
234+ <resourceexists >
235+ <file file =" ${ git.sh } " />
236+ </resourceexists >
237+ </condition >
238+
239+ <exec executable =" ${ exec.command } " >
240+ <arg line =" ${ exec.argline } " />
241+ </exec >
242+ <echo level =" info" ></echo >
243+ </target >
244+
245+ <target name =" cmake-generate" >
246+ <mkdir dir =" ${ cmake.generated.directory } " />
247+ <exec executable =" cmake" dir =" ${ cmake.generated.directory } " failonerror =" true" >
248+ <arg line =" ${ ant.project.basedir } " />
249+ <!-- Set the native lib output directory or leave blank to let CMake calculate -->
250+ <arg line =" ${ cmake.generator.nativelibdir } " />
251+ <!-- Pass-in maven's JAVA_HOME, helps resolve jni.h -->
252+ <arg line =" -DJAVA_HOME="${ java.home } "" />
253+ <!-- Final generator argument should be blank or one of:
254+ -DCMAKE_GENERATOR_PLATFORM=...
255+ -DCMAKE_TOOLCHAIN_FILE=...
256+ -DCMAKE_OSX_ARCHITECTURE=...
257+ -->
258+ <arg line =" ${ cmake.generator.arg } " />
259+ </exec >
260+ </target >
261+
262+ <target name =" cmake-build" >
263+ <!-- copy header jdk<=8 -->
264+ <copy todir =" ${ cmake.generated.directory } " flatten =" true" overwrite =" true" verbose =" true" failonerror =" false" quiet =" true" >
265+ <fileset dir =" ${ cmake.generated.directory } /../nar/" includes =" **/*.h" />
266+ </copy >
267+ <exec executable =" cmake" dir =" ${ cmake.generated.directory } " failonerror =" true" >
268+ <arg line =" --build" />
269+ <arg line =" ." />
270+ <arg line =" ${ cmake.build.arg } " />
271+ </exec >
272+ </target >
273+ </project >
0 commit comments