9
9
# this software. The contributing author, Izaak Beekman, retains all
10
10
# rights permitted by the terms of the JSON-Fortran license.
11
11
12
- cmake_minimum_required ( VERSION 3.5 FATAL_ERROR )
12
+ cmake_minimum_required ( VERSION 3.18 FATAL_ERROR )
13
+
14
+ option (JSONFORTRAN_ENABLE_DOC_GENERATION "Enable doc generation" OFF )
15
+ option (JSONFORTRAN_ENABLE_TESTS "Enable tests" OFF )
16
+ option (JSONFORTRAN_STATIC_LIBRARY_ONLY "Generate only static library" ON )
13
17
14
18
# Use MSVS folders to organize projects on windows
15
19
set_property (GLOBAL PROPERTY USE_FOLDERS ON )
@@ -164,8 +168,20 @@ endif ()
164
168
#---------------------------------------------
165
169
166
170
set ( LIB_NAME ${PROJECT_NAME} )
167
- add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
168
- add_library ( ${LIB_NAME} -static STATIC ${JF_LIB_SRCS} )
171
+ if (CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
172
+ add_library ( ${LIB_NAME} -obj OBJECT ${JF_LIB_SRCS} )
173
+ set_property (TARGET ${LIB_NAME} -obj PROPERTY POSITION_INDEPENDENT_CODE 1)
174
+
175
+ add_library ( ${LIB_NAME} SHARED $<TARGET_OBJECTS:${LIB_NAME} -obj> )
176
+ add_library ( ${LIB_NAME} -static STATIC $<TARGET_OBJECTS:${LIB_NAME} -obj> )
177
+ else ()
178
+ if (JSONFORTRAN_STATIC_LIBRARY_ONLY)
179
+ add_library ( ${LIB_NAME} STATIC ${JF_LIB_SRCS} )
180
+ add_library ( ${LIB_NAME} -static STATIC ${JF_LIB_SRCS} )
181
+ else ()
182
+ add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
183
+ endif ()
184
+ endif ()
169
185
170
186
# add an alias so that including json-fortran is agnostic
171
187
# of find_package or being directly compiled through add_subdirectory
@@ -187,15 +203,26 @@ target_include_directories(${LIB_NAME}-static
187
203
PUBLIC
188
204
$<BUILD_INTERFACE:${MODULE_DIR} >
189
205
$<INSTALL_INTERFACE:${INSTALL_MOD_DIR} >)
190
- set_target_properties ( ${LIB_NAME} -static
191
- PROPERTIES
192
- OUTPUT_NAME ${LIB_NAME}
193
- if (NOT MSVC_IDE )
194
- PREFIX lib
195
- endif ()
196
- VERSION ${PROJECT_VERSION}
197
- ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib
198
- Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
206
+ if (CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
207
+ set_target_properties ( ${LIB_NAME} -static
208
+ PROPERTIES
209
+ if (NOT MSVC_IDE )
210
+ PREFIX lib
211
+ endif ()
212
+ VERSION ${PROJECT_VERSION}
213
+ ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib
214
+ Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
215
+ else ()
216
+ set_target_properties ( ${LIB_NAME} -static
217
+ PROPERTIES
218
+ OUTPUT_NAME ${LIB_NAME}
219
+ if (NOT MSVC_IDE )
220
+ PREFIX lib
221
+ endif ()
222
+ VERSION ${PROJECT_VERSION}
223
+ ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR} /lib
224
+ Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
225
+ endif ()
199
226
set_target_properties ( ${LIB_NAME}
200
227
PROPERTIES
201
228
OUTPUT_NAME ${LIB_NAME}
@@ -210,8 +237,12 @@ set_target_properties ( ${LIB_NAME}
210
237
#-------------------------------------
211
238
# Build the documentation with FORD
212
239
#-------------------------------------
213
- set ( SKIP_DOC_GEN FALSE CACHE BOOL
214
- "Disable building the API documentation with FORD" )
240
+ if (JSONFORTRAN_ENABLE_DOC_GENERATION)
241
+ set (SKIP_DOC_GEN FALSE CACHE BOOL "Disable building the API documentation with FORD" )
242
+ else ()
243
+ set (SKIP_DOC_GEN TRUE CACHE BOOL "Disable building the API documentation with FORD" )
244
+ endif ()
245
+
215
246
if ( NOT SKIP_DOC_GEN )
216
247
find_program ( FORD ford )
217
248
if ( FORD ) # Found
@@ -284,8 +315,11 @@ endif ()
284
315
#--------------------------
285
316
# Handle test related stuff
286
317
#--------------------------
287
- set ( ENABLE_TESTS TRUE CACHE BOOL
288
- "Enable the JSON-Fortran tests." )
318
+ if (JSONFORTRAN_ENABLE_TESTS)
319
+ set ( ENABLE_TESTS TRUE CACHE BOOL "Enable the JSON-Fortran tests." )
320
+ else ()
321
+ set ( ENABLE_TESTS FALSE CACHE BOOL "Enable the JSON-Fortran tests." )
322
+ endif ()
289
323
290
324
#---------------------------------------------------------------------
291
325
# Add some tests to ensure that the software is performing as expected
0 commit comments