-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
234 lines (202 loc) · 7.63 KB
/
CMakeLists.txt
File metadata and controls
234 lines (202 loc) · 7.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# CMake build configuration for the Access Layer Java HLI
cmake_minimum_required( VERSION 3.16 )
# Configuration options for common assets
################################################################################
option( AL_DOWNLOAD_DEPENDENCIES "Automatically download assets from the AL git repository" ON )
set( AL_CORE_GIT_REPOSITORY "ssh://git@git.iter.org/imas/al-core.git" CACHE STRING "Git repository of AL-core" )
set( AL_CORE_VERSION "main" CACHE STRING "Git commit/tag/branch of AL-core" )
include(FetchContent)
# Load common assets
################################################################################
if( DEFINED ENV{AL_COMMON_PATH} )
# Take common assets from the path in this environment variable instead of al-core
set( AL_COMMON_PATH $ENV{AL_COMMON_PATH} )
else()
if( ${AL_DOWNLOAD_DEPENDENCIES} )
# Download common assets from the ITER git:
FetchContent_Declare(
al-core
GIT_REPOSITORY "${AL_CORE_GIT_REPOSITORY}"
GIT_TAG "${AL_CORE_VERSION}"
)
else()
FetchContent_Declare(
al-core
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../al-core"
)
endif()
FetchContent_MakeAvailable( al-core )
set( AL_COMMON_PATH "${al-core_SOURCE_DIR}/common" )
endif()
add_subdirectory( ${AL_COMMON_PATH} _common )
# Define project
################################################################################
# Set VERSION and FULL_VERSION from `git describe`:
set( GIT_ARCHIVE_DESCRIBE [[$Format:%(describe)$]] )
include( ALDetermineVersion )
project( al-java
VERSION ${VERSION}
DESCRIPTION "Java High Level Interface of the IMAS Access Layer"
HOMEPAGE_URL "https://imas.iter.org/"
LANGUAGES C CXX
)
if( NOT PROJECT_VERSION_TWEAK EQUAL 0 )
message( "Building a development version of the Access Layer Java HLI" )
endif()
# Compiler settings
include( ALSetCompilerFlags )
# Common HLI options
include( ALCommonConfig )
# Data dictionary
include( ALBuildDataDictionary )
# AL core, plugins and documentation
include( ALCore )
# Stop processing when only building documentation
if( AL_DOCS_ONLY )
return()
endif()
# Dependencies
################################################################################
find_package( JNI REQUIRED )
find_package( Java REQUIRED )
include( UseJava )
find_package( SaxonHE )
# Find LibXslt for the xsltproc program
find_package( LibXslt QUIET )
if( NOT LIBXSLT_XSLTPROC_EXECUTABLE )
message( FATAL_ERROR "Could not find xsltproc" )
endif()
# Generate sources
################################################################################
set( GENERATED_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/src/imasjava" )
set( GENERATED_SOURCES "${GENERATED_SRC_DIR}/imas.java" )
foreach( IDS_NAME IN LISTS IDS_NAMES )
list( APPEND GENERATED_SOURCES "${GENERATED_SRC_DIR}/ids/${IDS_NAME}_IDSBase.java" )
endforeach()
add_custom_command(
# Use a dummy output file: when listing all actual output files (which are
# source files of target `al-java`), they would be re-created with every build.
OUTPUT ${GENERATED_SRC_DIR}/dummy.txt
# Generate source files with saxon
COMMAND
java -cp ${SaxonHE_CLASSPATH}
net.sf.saxon.Transform -t -warnings:fatal
"-xsl:${CMAKE_CURRENT_SOURCE_DIR}/IDSDef2Java.xsl"
"-s:${IDSDEF}"
DD_VERSION=${DD_VERSION}
AL_VERSION=${FULL_VERSION}
SYSTEM=${CMAKE_SYSTEM_NAME}
# Create/update our dummy file
COMMAND ${CMAKE_COMMAND} -E touch ${GENERATED_SRC_DIR}/dummy.txt
DEPENDS IDSDef2Java.xsl ${IDSDEF}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target( al-java-sources
COMMAND ${CMAKE_COMMAND} -E echo ""
DEPENDS ${GENERATED_SRC_DIR}/dummy.txt
# Actually these are results of the custom_command above, but with this trick
# we don't rebuild it always (only when IDSDef.xml or the xslts have changed)
BYPRODUCTS ${GENERATED_SOURCES}
)
set( SOURCES ${GENERATED_SOURCES} )
list( APPEND SOURCES
src/imasjava/ALException.java
src/imasjava/ALLowLevel.java
src/imasjava/Complex.java
src/imasjava/CoordinateValidation.java
src/imasjava/LimitedSizeStringBuilder.java
src/imasjava/StringLimitException.java
src/imasjava/SummaryString.java
src/imasjava/ValidationException.java
src/imasjava/Vect1DBoolean.java
src/imasjava/Vect1DComplex.java
src/imasjava/Vect1DDouble.java
src/imasjava/Vect1DFloat.java
src/imasjava/Vect1DInt.java
src/imasjava/Vect1DString.java
src/imasjava/Vect2DComplex.java
src/imasjava/Vect2DDouble.java
src/imasjava/Vect2DFloat.java
src/imasjava/Vect2DInt.java
src/imasjava/Vect3DComplex.java
src/imasjava/Vect3DDouble.java
src/imasjava/Vect3DFloat.java
src/imasjava/Vect3DInt.java
src/imasjava/Vect4DComplex.java
src/imasjava/Vect4DDouble.java
src/imasjava/Vect5DComplex.java
src/imasjava/Vect5DDouble.java
src/imasjava/Vect6DComplex.java
src/imasjava/Vect6DDouble.java
src/imasjava/Vect7DComplex.java
src/imasjava/Vect7DDouble.java
src/imasjava/VectComplex.java
src/imasjava/VectGeneric.java
src/imasjava/utilities/ImasReflection.java
src/imasjava/wrapper/LowLevel.java
src/imasjava/wrapper/Wrapper.java
)
# Generate sources (identifiers)
################################################################################
# Note: identifiers.xsl tries to import identifiers.common.xsl
# Unfortunately, xsl:include doesn't support parameters, so we need to put them together
# in the build folder:
file( CREATE_LINK
"${al-common_SOURCE_DIR}/identifiers.common.xsl"
"${CMAKE_CURRENT_BINARY_DIR}/identifiers.common.xsl"
SYMBOLIC COPY_ON_ERROR
)
file( CREATE_LINK
"${CMAKE_CURRENT_SOURCE_DIR}/identifiers.xsl"
"${CMAKE_CURRENT_BINARY_DIR}/identifiers.xsl"
SYMBOLIC COPY_ON_ERROR
)
set( IDENTIFIER_SRC_DIR ${CMAKE_CURRENT_BINARY_DIR}/identifiers/src/ )
set( IDENTIFIER_SOURCES )
foreach( ID_FILE IN LISTS DD_IDENTIFIER_FILES )
# cmake_path( GET ID_FILE STEM ID_NAME)
string( REGEX REPLACE "(^.*[/\\]|[.]xml$)" "" ID_NAME ${ID_FILE} )
set( SOURCE_NAME "${IDENTIFIER_SRC_DIR}/${ID_NAME}.java" )
add_custom_command(
OUTPUT ${SOURCE_NAME} ${HEADER_NAME}
COMMAND ${CMAKE_COMMAND} -E make_directory ${IDENTIFIER_SRC_DIR}
COMMAND ${LIBXSLT_XSLTPROC_EXECUTABLE}
--stringparam name ${ID_NAME}
--stringparam prefix ${IDENTIFIER_SRC_DIR}
${CMAKE_CURRENT_BINARY_DIR}/identifiers.xsl
${ID_FILE}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/identifiers.xsl
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
list( APPEND IDENTIFIER_SOURCES ${SOURCE_NAME} )
endforeach()
# Targets
################################################################################
add_library( al-java-binding SHARED wrapper/imasjava_wrapper_LowLevel.cpp )
target_include_directories( al-java-binding PRIVATE ${JNI_INCLUDE_DIRS} "wrapper" )
target_link_libraries( al-java-binding al )
# Store lib-al-java-binding.so in the lib/ folder (required to run examples)
set_target_properties( al-java-binding PROPERTIES LIBRARY_OUTPUT_DIRECTORY lib )
# https://cmake.org/cmake/help/latest/module/UseJava.html#add-jar
add_jar( al-java
SOURCES ${SOURCES}
OUTPUT_NAME imas
)
add_dependencies( al-java al-java-binding )
add_jar( al-identifiers-java
SOURCES ${IDENTIFIER_SOURCES}
INCLUDE_JARS al-java
OUTPUT_NAME al-identifiers
)
add_dependencies( al-identifiers-java al-java )
# Install
################################################################################
install( TARGETS al-java-binding )
install_jar( al-java DESTINATION jar )
install_jar( al-identifiers-java DESTINATION jar )
# Tests
################################################################################
# No "test" rule existed in Makefile
if( AL_EXAMPLES )
add_subdirectory( examples )
endif()