Skip to content

Commit 5a54b62

Browse files
committed
Adjust maven profiles
- Adds -DNATIVE_LIB_DIR option - Adds boilerplate mingw profiles - Fixes building with MSVC
1 parent 5c096b9 commit 5a54b62

File tree

2 files changed

+88
-22
lines changed

2 files changed

+88
-22
lines changed

CMakeLists.txt

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
cmake_minimum_required(VERSION 3.0)
22
cmake_policy(SET CMP0048 NEW)
33
cmake_policy(SET CMP0042 NEW)
4+
45
project(jssc VERSION 2.7.1 LANGUAGES CXX)
56

7+
8+
69
find_package(Java)
710
find_package(JNI)
811

@@ -65,33 +68,37 @@ list(APPEND JSSC_ADDITIONAL_INCLUDES target/nar/javah-include/)
6568
# output to maven conventions to target/generated-sources/<generator>
6669
# The other part will be in conventions to native-lib-loader.
6770

68-
# linux, macos, etc
69-
string(TOLOWER "${CMAKE_SYSTEM_NAME}" OS_NAME)
70-
if(APPLE)
71-
# See <native.lib.directory> in pox.xml
72-
set(OS_NAME "osx")
73-
endif()
71+
# Detect platform if -DNATIVE_LIB_DIR is not provided
72+
# TODO: Handle arm, hardfloat, etc
73+
if(NOT NATIVE_LIB_DIR)
74+
# windows, linux, darwin, etc
75+
string(TOLOWER "${CMAKE_SYSTEM_NAME}" OS_NAME)
7476

75-
# 32-bit or 64-bit
76-
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
77-
set(OS_BITS 64)
78-
else()
79-
set(OS_BITS 32)
77+
# 32-bit or 64-bit
78+
#FIXME: Might fail on cross-compile
79+
if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
80+
set(OS_BITS 64)
81+
else()
82+
set(OS_BITS 32)
83+
endif()
84+
SET(NATIVE_LIB_DIR ${OS_NAME}_${OS_BITS})
8085
endif()
8186

82-
# library (e.g. linux_64.so) TODO: Handle arm, hardfloat, etc
83-
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../classes/META-INF/lib/${OS_NAME}_${OS_BITS})
87+
# library (e.g. /linux_64/)
88+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ../classes/META-INF/lib/${NATIVE_LIB_DIR})
8489

85-
add_library(jssc SHARED
86-
src/cpp/${JSSC_PLATFORM}/jssc.cpp
87-
)
90+
add_library(jssc SHARED src/cpp/${JSSC_PLATFORM}/jssc.cpp)
8891

8992
target_include_directories(jssc PRIVATE ${JNI_INCLUDE_DIRS} ${JSSC_ADDITIONAL_INCLUDES})
9093

9194
set_target_properties(jssc PROPERTIES VERSION ${PROJECT_VERSION})
9295
set_target_properties(jssc PROPERTIES PUBLIC_HEADER target/nar/javah-include/jssc_SerialNativeInterface.h)
9396
set_target_properties(jssc PROPERTIES POSITION_INDEPENDENT_CODE ON)
94-
97+
if(MSVC)
98+
# Fix paths for Debug/Release
99+
set_target_properties(jssc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
100+
set_target_properties(jssc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}")
101+
endif()
95102

96103
# Call strip on non-debug builds
97104
if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb")

pom.xml

+64-5
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@
1919
<cmake.download.binaries>false</cmake.download.binaries>
2020
<!-- cmake maven plugin -->
2121
<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>
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>
2431
<!-- native lib loader (dependency) -->
2532
<native.lib.directory>linux_64</native.lib.directory>
2633
</properties>
@@ -91,11 +98,13 @@
9198
<targetPath>${project.build.directory}/cmake</targetPath>
9299
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
93100
<generator>${cmake.generator}</generator>
94-
<!--TODO Use -DCMAKE_TOOLCHAIN_FILE file for cross-compile
95101
<options>
96-
<option>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw64.cmake</option>
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>
97107
</options>
98-
-->
99108
</configuration>
100109
</execution>
101110

@@ -162,11 +171,60 @@
162171
</os>
163172
</activation>
164173
<properties>
174+
<native.lib.directory>windows_64</native.lib.directory>
165175
<cmake.root.dir>${env.PROGRAMFILES}/CMake</cmake.root.dir>
166176
<!--FIXME "Makefiles" parameter MUST be optional see cmake-maven-project/cmake-maven-project#7 -->
167177
<cmake.generator>Visual Studio 14 2015</cmake.generator>
168178
<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>
182+
</properties>
183+
</profile>
184+
185+
<!-- cmake windows-x86 profile -->
186+
<profile>
187+
<id>cmake-win32</id>
188+
<activation>
189+
<os>
190+
<family>Windows</family>
191+
<arch>x86</arch>
192+
</os>
193+
</activation>
194+
<properties>
195+
<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 -->
198+
<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>
202+
</properties>
203+
</profile>
204+
205+
<!-- mingw32 profile -->
206+
<!-- TODO: Untested. Test this mingw32 profile: "mvn -P cmake-mingw32 install" -->
207+
<profile>
208+
<id>cmake-mingw32</id>
209+
<properties>
210+
<native.lib.directory>windows_32</native.lib.directory>
211+
<cmake.generator>Unix Makefiles</cmake.generator>
212+
<cmake.classifier>windows-x86_32</cmake.classifier>
213+
<cmake.option.first>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw32.cmake</cmake.option.first>
214+
<cmake.option.second>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.second>
215+
</properties>
216+
</profile>
217+
218+
<!-- mingw64 profile -->
219+
<!-- TODO: Untested. Test this mingw64 profile: "mvn -P cmake-mingw64 install" -->
220+
<profile>
221+
<id>cmake-mingw64</id>
222+
<properties>
169223
<native.lib.directory>windows_64</native.lib.directory>
224+
<cmake.generator>Unix Makefiles</cmake.generator>
225+
<cmake.classifier>windows-x86_64</cmake.classifier>
226+
<cmake.option.first>-DCMAKE_TOOLCHAIN_FILE=toolchain/Mingw64.cmake</cmake.option.first>
227+
<cmake.option.second>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.second>
170228
</properties>
171229
</profile>
172230

@@ -183,6 +241,7 @@
183241
<cmake.root.dir>/usr/local</cmake.root.dir>
184242
<cmake.classifier>mac-x86_64</cmake.classifier>
185243
<native.lib.directory>osx_64</native.lib.directory>
244+
<cmake.option.first>-DNATIVE_LIB_DIR=${native.lib.directory}</cmake.option.first>
186245
</properties>
187246

188247
</profile>

0 commit comments

Comments
 (0)