Skip to content

Commit c1e1544

Browse files
committed
Work towards #4 and replace the cmake-maven-plugin with the maven-antrun-plugin.
- Options from previous cmake-plugin-execution added. - Working directories added. - Environment variables still need to be done. - Added another test which currently fails (to highlight a known problem). - Not tested on MacOS or Windows.
1 parent 4a7dd07 commit c1e1544

File tree

3 files changed

+71
-64
lines changed

3 files changed

+71
-64
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ target/
3737

3838
# IDE files: IntellIJ
3939
.idea/
40+
*.iml
4041

4142
# IDE files: eclipse
4243
.settings/

pom.xml

+55-64
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@
1616

1717
<!-- skip javah execution for java9+, see profile below. -->
1818
<javah.skip>false</javah.skip>
19-
<cmake.download.binaries>false</cmake.download.binaries>
20-
<!-- cmake maven plugin -->
21-
<cmake.classifier>linux-x86_64</cmake.classifier>
22-
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
23-
<cmake.generator>Unix Makefiles</cmake.generator>
24-
<!-- Additional command-line options, last prevents warnings on unused options -->
25-
<!--FIXME empty option tag throw NPE see cmake-maven-project/cmake-maven-project#24 -->
26-
<cmake.option.first>-DFIRST=empty</cmake.option.first>
27-
<cmake.option.second>-DSECOND=empty</cmake.option.second>
28-
<cmake.option.third>-DTHIRD=empty</cmake.option.third>
29-
<cmake.option.fourth>-DFOURTH=empty</cmake.option.fourth>
30-
<cmake.option.last>--no-warn-unused-cli</cmake.option.last>
3119
<!-- native lib loader (dependency) -->
3220
<native.lib.directory>linux_64</native.lib.directory>
21+
22+
<!-- custom directories and file paths -->
23+
<cmake.generated.directory>${project.build.directory}/cmake</cmake.generated.directory>
24+
<cmake.liststxt.path>${project.basedir}/CMakeLists.txt</cmake.liststxt.path>
25+
26+
<!-- custom cmake options -->
27+
<cmake.generate.args></cmake.generate.args>
28+
<cmake.build.args></cmake.build.args>
29+
<!-- options given in compile phase after double dashes. -->
30+
<cmake.buildtool.args></cmake.buildtool.args>
31+
32+
<!-- dependency versions -->
33+
<dependency.nativelibloader.version>2.0.2</dependency.nativelibloader.version>
34+
35+
<!-- plugin versions -->
36+
<plugin.antrun.version>1.8</plugin.antrun.version>
37+
<plugin.nar.version>3.6.0</plugin.nar.version>
3338
</properties>
3439

3540
<dependencies>
3641
<dependency>
3742
<groupId>org.scijava</groupId>
3843
<artifactId>native-lib-loader</artifactId>
39-
<version>2.0.2</version>
44+
<version>${dependency.nativelibloader.version}</version>
4045
</dependency>
4146
<dependency>
4247
<groupId>junit</groupId>
@@ -59,7 +64,7 @@
5964
<plugin>
6065
<groupId>com.github.maven-nar</groupId>
6166
<artifactId>nar-maven-plugin</artifactId>
62-
<version>3.6.0</version>
67+
<version>${plugin.nar.version}</version>
6368
<extensions>true</extensions>
6469

6570
<executions>
@@ -78,48 +83,48 @@
7883

7984
<!-- execute cmake -->
8085
<plugin>
81-
<groupId>com.googlecode.cmake-maven-project</groupId>
82-
<artifactId>cmake-maven-plugin</artifactId>
83-
<version>3.7.2-b1</version>
84-
85-
<configuration>
86-
<downloadBinaries>${cmake.download.binaries}</downloadBinaries>
87-
<classifier>${cmake.classifier}</classifier>
88-
</configuration>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-antrun-plugin</artifactId>
88+
<version>${plugin.antrun.version}</version>
8989

9090
<executions>
9191
<execution>
9292
<id>cmake-generate</id>
93-
<goals>
94-
<goal>generate</goal>
95-
</goals>
93+
<goals><goal>run</goal></goals>
94+
<phase>generate-sources</phase>
9695
<configuration>
97-
<sourcePath>${project.basedir}</sourcePath>
98-
<targetPath>${project.build.directory}/cmake</targetPath>
99-
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
100-
<generator>${cmake.generator}</generator>
101-
<options>
102-
<option>${cmake.option.first}</option>
103-
<option>${cmake.option.second}</option>
104-
<option>${cmake.option.third}</option>
105-
<option>${cmake.option.fourth}</option>
106-
<option>${cmake.option.last}</option>
107-
</options>
96+
<target name="cmake-generate">
97+
<mkdir dir="${cmake.generated.directory}" />
98+
99+
<exec executable="cmake" dir="${cmake.generated.directory}" failonerror="true">
100+
<arg line="${project.basedir}" />
101+
<arg line="--no-warn-unused-cli" />
102+
<arg line="${cmake.generate.args}" />
103+
</exec>
104+
</target>
108105
</configuration>
109106
</execution>
110107

111108
<execution>
112109
<id>cmake-compile</id>
113-
<goals>
114-
<goal>compile</goal>
115-
</goals>
110+
<goals><goal>run</goal></goals>
111+
<phase>compile</phase>
116112
<configuration>
117-
<projectDirectory>${project.build.directory}/cmake</projectDirectory>
113+
<target name="cmake-build">
114+
<exec executable="cmake" dir="${project.basedir}" failonerror="true">
115+
<arg line="--build" />
116+
<arg line="${cmake.generated.directory}" />
117+
<arg line="${cmake.build.args}" />
118+
<arg line="--" />
119+
<arg line="${cmake.buildtool.args}" />
120+
</exec>
121+
</target>
118122
</configuration>
119123
</execution>
120124
</executions>
121125
</plugin>
122126

127+
123128
<plugin>
124129
<groupId>org.apache.maven.plugins</groupId>
125130
<artifactId>maven-surefire-plugin</artifactId>
@@ -172,13 +177,9 @@
172177
</activation>
173178
<properties>
174179
<native.lib.directory>windows_64</native.lib.directory>
175-
<cmake.root.dir>${env.PROGRAMFILES}/CMake</cmake.root.dir>
176-
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
177180
<cmake.generator>Visual Studio 14 2015</cmake.generator>
178-
<cmake.classifier>windows-x86_64</cmake.classifier>
179-
<cmake.option.first>--config Release</cmake.option.first>
180-
<cmake.option.second>-DCMAKE_GENERATOR_PLATFORM=x64</cmake.option.second>
181-
<cmake.option.third>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.third>
181+
<cmake.generate.args>-G "${cmake.generator}" --config Release -DCMAKE_GENERATOR_PLATFORM=x64 -DNATIVE_LIB_DIR=${native.lib.directory}</cmake.generate.args>
182+
<cmake.build.args>${cmake.generate.args}</cmake.build.args>
182183
</properties>
183184
</profile>
184185

@@ -193,12 +194,9 @@
193194
</activation>
194195
<properties>
195196
<native.lib.directory>windows_32</native.lib.directory>
196-
<cmake.root.dir>${env.PROGRAMFILES}/CMake</cmake.root.dir>
197-
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
198197
<cmake.generator>Visual Studio 14 2015</cmake.generator>
199-
<cmake.classifier>windows-x86_32</cmake.classifier>
200-
<cmake.option.first>--config Release</cmake.option.first>
201-
<cmake.option.second>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.second>
198+
<cmake.generate.args>-G "${cmake.generator}" --config Release -DNATIVE_LIB_DIR=${native.lib.directory}</cmake.generate.args>
199+
<cmake.build.args>${cmake.generate.args}</cmake.build.args>
202200
</properties>
203201
</profile>
204202

@@ -207,11 +205,8 @@
207205
<id>cmake-mingw32</id>
208206
<properties>
209207
<native.lib.directory>windows_32</native.lib.directory>
210-
<cmake.generator>Unix Makefiles</cmake.generator>
211-
<cmake.classifier>windows-x86_32</cmake.classifier>
212-
<cmake.option.first>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw32.cmake</cmake.option.first>
213-
<cmake.option.second>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.second>
214-
<cmake.child.dir>bin/cmake</cmake.child.dir>
208+
<cmake.generate.args>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw32.cmake -DNATIVE_LIB_DIR=${native.lib.directory}</cmake.generate.args>
209+
<cmake.build.args>${cmake.generate.args}</cmake.build.args>
215210
</properties>
216211
</profile>
217212

@@ -220,11 +215,8 @@
220215
<id>cmake-mingw64</id>
221216
<properties>
222217
<native.lib.directory>windows_64</native.lib.directory>
223-
<cmake.generator>Unix Makefiles</cmake.generator>
224-
<cmake.classifier>windows-x86_64</cmake.classifier>
225-
<cmake.option.first>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw64.cmake</cmake.option.first>
226-
<cmake.option.second>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.second>
227-
<cmake.child.dir>bin/cmake</cmake.child.dir>
218+
<cmake.generate.args>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw64.cmake -DNATIVE_LIB_DIR=${native.lib.directory</cmake.generate.args>
219+
<cmake.build.args>${cmake.generate.args}</cmake.build.args>
228220
</properties>
229221
</profile>
230222

@@ -238,10 +230,9 @@
238230
</activation>
239231
<properties>
240232
<!-- final dir is: ${cmake.root.dir}/${cmake.child.dir} -->
241-
<cmake.root.dir>/usr/local</cmake.root.dir>
242-
<cmake.classifier>mac-x86_64</cmake.classifier>
243233
<native.lib.directory>osx_64</native.lib.directory>
244-
<cmake.option.first>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.first>
234+
<cmake.generate.args>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.generate.args>
235+
<cmake.build.args>${cmake.generate.args}</cmake.build.args>
245236
</properties>
246237

247238
</profile>

src/test/java/jssc/SerialNativeInterfaceTest.java

+15
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
import static org.hamcrest.CoreMatchers.is;
66
import static org.hamcrest.CoreMatchers.not;
7+
import static org.hamcrest.CoreMatchers.nullValue;
78
import static org.junit.Assert.assertThat;
9+
import static org.junit.Assert.fail;
810

911
public class SerialNativeInterfaceTest {
1012

@@ -24,4 +26,17 @@ public void testInitNativeInterface() {
2426
}
2527
}
2628

29+
@Test
30+
public void testPrintVersion() {
31+
try {
32+
final String nativeLibraryVersion = SerialNativeInterface.getNativeLibraryVersion();
33+
assertThat(nativeLibraryVersion, is(not(nullValue())));
34+
assertThat(nativeLibraryVersion, is(not("")));
35+
} catch (UnsatisfiedLinkError linkError) {
36+
linkError.printStackTrace();
37+
fail("Should be able to call method!");
38+
}
39+
40+
}
41+
2742
}

0 commit comments

Comments
 (0)