1
- cmake_minimum_required (VERSION 3.9)
2
- project (jssc VERSION 2.8.0 DESCRIPTION "Java Simple Serial Connector" )
1
+ cmake_minimum_required (VERSION 3.0)
2
+ cmake_policy (SET CMP0048 NEW)
3
+ cmake_policy (SET CMP0042 NEW)
4
+
5
+ project (jssc VERSION 2.7.1 LANGUAGES CXX)
3
6
4
7
find_package (Java)
5
8
find_package (JNI)
@@ -56,15 +59,60 @@ else()
56
59
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O2" )
57
60
endif ()
58
61
59
- add_library (jssc SHARED
60
- src/cpp/${JSSC_PLATFORM} /jssc.cpp
61
- )
62
+ # Detect platform if -DNATIVE_LIB_DIR is not provided
63
+ # TODO: Handle arm, hardfloat, etc
64
+ if (NOT NATIVE_LIB_DIR)
65
+ # windows, linux, darwin, etc
66
+ string (TOLOWER "${CMAKE_SYSTEM_NAME} " OS_NAME)
67
+ if (OS_NAME MATCHES "darwin" )
68
+ set (OS_NAME "osx" )
69
+ endif ()
70
+
71
+ # 32-bit or 64-bit
72
+ #FIXME: Might fail on cross-compile
73
+ if ("${CMAKE_SIZEOF_VOID_P} " EQUAL "8" )
74
+ set (OS_BITS 64)
75
+ else ()
76
+ set (OS_BITS 32)
77
+ endif ()
78
+ SET (NATIVE_LIB_DIR ${OS_NAME} _${OS_BITS} )
79
+ endif ()
80
+ set (CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} /natives/${NATIVE_LIB_DIR} )
81
+
82
+ # version.h using #cmakedefine for version from pom.xml.
83
+ set (JSSC_VERSION "0.0.0-UNKNOWN" )
84
+ file (STRINGS ${CMAKE_CURRENT_SOURCE_DIR} /pom.xml POM_FILE)
85
+ foreach (POM_LINE ${POM_FILE} )
86
+ # Assume first "<version>" is the project version
87
+ if (POM_LINE MATCHES "<version>" )
88
+ string (REGEX REPLACE "^[ \t ]+|<[^>]*>" "" DETECTED_VERSION "${POM_LINE} " )
89
+ string (STRIP "${DETECTED_VERSION} " DETECTED_VERSION)
90
+ if (DETECTED_VERSION STREQUAL "" )
91
+ MESSAGE (WARNING "Could not parse version from pom.xml, defaulting to \" ${JSSC_VERSION} \" " )
92
+ else ()
93
+ SET (JSSC_VERSION "${DETECTED_VERSION} " )
94
+ MESSAGE (STATUS "Found version \" ${JSSC_VERSION} \" in pom.xml" )
95
+ endif ()
96
+ break ()
97
+ endif ()
98
+ endforeach ()
99
+ configure_file (src/cpp/version .h.in ${CMAKE_CURRENT_BINARY_DIR} /version .h @ONLY)
100
+
101
+ add_library (jssc SHARED src/cpp/${JSSC_PLATFORM} /jssc.cpp)
62
102
63
- target_include_directories (jssc PRIVATE ${JNI_INCLUDE_DIRS} ${JSSC_ADDITIONAL_INCLUDES} )
103
+ target_include_directories (jssc PRIVATE ${JNI_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR} ${ JSSC_ADDITIONAL_INCLUDES} )
64
104
65
- set_target_properties (jssc PROPERTIES VERSION ${PROJECT_VERSION} )
66
- set_target_properties (jssc PROPERTIES PUBLIC_HEADER src/jssc_SerialNativeInterface.h)
105
+ set_target_properties (jssc PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_BINARY_DIR} /jssc_SerialNativeInterface.h)
67
106
set_target_properties (jssc PROPERTIES POSITION_INDEPENDENT_CODE ON )
107
+ if (WIN32 )
108
+ # Fix paths for MSVC (Debug/Release) and MINGW
109
+ set_target_properties (jssc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_LIBRARY_OUTPUT_DIRECTORY} " )
110
+ set_target_properties (jssc PROPERTIES RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_LIBRARY_OUTPUT_DIRECTORY} " )
111
+ endif ()
112
+ if (FORCE_M32)
113
+ # Build 32-bit binary on Linux
114
+ set_target_properties (jssc PROPERTIES COMPILE_FLAGS -m32 LINK_FLAGS -m32)
115
+ endif ()
68
116
69
117
# Call strip on non-debug builds
70
118
if (CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb" )
@@ -73,3 +121,12 @@ if(CMAKE_STRIP AND NOT CMAKE_BUILD_TYPE MATCHES "Deb")
73
121
endif ()
74
122
add_custom_command (TARGET jssc POST_BUILD COMMAND "${CMAKE_STRIP} " ${STRIP_ARGS} $<TARGET_FILE:jssc>)
75
123
endif ()
124
+
125
+ # Handle compiler warnings
126
+ if (MSVC )
127
+ #TODO Treat warnings as errors /WX
128
+ target_compile_options (jssc PRIVATE /W4)
129
+ else ()
130
+ #TODO Treat warnings as errors -Werror
131
+ target_compile_options (jssc PRIVATE -Wall -Wextra -pedantic)
132
+ endif ()
0 commit comments