99# this software. The contributing author, Izaak Beekman, retains all
1010# rights permitted by the terms of the JSON-Fortran license.
1111
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 )
1317
1418# Use MSVS folders to organize projects on windows
1519set_property (GLOBAL PROPERTY USE_FOLDERS ON )
@@ -164,8 +168,20 @@ endif ()
164168#---------------------------------------------
165169
166170set ( 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 ()
169185
170186# add an alias so that including json-fortran is agnostic
171187# of find_package or being directly compiled through add_subdirectory
@@ -187,15 +203,26 @@ target_include_directories(${LIB_NAME}-static
187203 PUBLIC
188204 $<BUILD_INTERFACE:${MODULE_DIR} >
189205 $<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 ()
199226set_target_properties ( ${LIB_NAME}
200227 PROPERTIES
201228 OUTPUT_NAME ${LIB_NAME}
@@ -210,8 +237,12 @@ set_target_properties ( ${LIB_NAME}
210237#-------------------------------------
211238# Build the documentation with FORD
212239#-------------------------------------
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+
215246if ( NOT SKIP_DOC_GEN )
216247 find_program ( FORD ford )
217248 if ( FORD ) # Found
@@ -284,8 +315,11 @@ endif ()
284315#--------------------------
285316# Handle test related stuff
286317#--------------------------
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 ()
289323
290324#---------------------------------------------------------------------
291325# Add some tests to ensure that the software is performing as expected
0 commit comments