Skip to content

Commit 94f7176

Browse files
committed
Fixes compilation with Ninja and IntelLLVM when using OneAPI
1 parent 7819919 commit 94f7176

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

CMakeLists.txt

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,16 @@ endif ()
167167
#---------------------------------------------
168168

169169
set ( LIB_NAME ${PROJECT_NAME} )
170-
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
171-
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
170+
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
171+
add_library ( ${LIB_NAME}-obj OBJECT ${JF_LIB_SRCS} )
172+
set_property(TARGET ${LIB_NAME}-obj PROPERTY POSITION_INDEPENDENT_CODE 1)
173+
174+
add_library ( ${LIB_NAME} SHARED $<TARGET_OBJECTS:${LIB_NAME}-obj> )
175+
add_library ( ${LIB_NAME}-static STATIC $<TARGET_OBJECTS:${LIB_NAME}-obj> )
176+
else()
177+
add_library ( ${LIB_NAME} SHARED ${JF_LIB_SRCS} )
178+
add_library ( ${LIB_NAME}-static STATIC ${JF_LIB_SRCS} )
179+
endif()
172180

173181
if(JSON_FORTRAN_USE_OpenCoarrays)
174182
target_link_libraries(${LIB_NAME}
@@ -185,15 +193,26 @@ target_include_directories(${LIB_NAME}-static
185193
PUBLIC
186194
$<BUILD_INTERFACE:${MODULE_DIR}>
187195
$<INSTALL_INTERFACE:${INSTALL_MOD_DIR}>)
188-
set_target_properties ( ${LIB_NAME}-static
189-
PROPERTIES
190-
OUTPUT_NAME ${LIB_NAME}
191-
if(NOT MSVC_IDE)
192-
PREFIX lib
193-
endif()
194-
VERSION ${VERSION}
195-
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
196-
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
196+
if(CMAKE_Fortran_COMPILER_ID STREQUAL IntelLLVM)
197+
set_target_properties ( ${LIB_NAME}-static
198+
PROPERTIES
199+
if(NOT MSVC_IDE)
200+
PREFIX lib
201+
endif()
202+
VERSION ${VERSION}
203+
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
204+
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
205+
else()
206+
set_target_properties ( ${LIB_NAME}-static
207+
PROPERTIES
208+
OUTPUT_NAME ${LIB_NAME}
209+
if(NOT MSVC_IDE)
210+
PREFIX lib
211+
endif()
212+
VERSION ${VERSION}
213+
ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib
214+
Fortran_MODULE_DIRECTORY ${MODULE_DIR} )
215+
endif()
197216
set_target_properties ( ${LIB_NAME}
198217
PROPERTIES
199218
OUTPUT_NAME ${LIB_NAME}

0 commit comments

Comments
 (0)