Skip to content

Commit

Permalink
CMake: Split fortran/c libs
Browse files Browse the repository at this point in the history
  • Loading branch information
jschueller committed Dec 26, 2023
1 parent 3126d51 commit 94be275
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/allow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ endmacro
evals
primac
primaf
primafc
cintrf
COBJ
COBJCON
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ option (PRIMA_ENABLE_C "C binding" ON)
if (PRIMA_ENABLE_C)
enable_language(C)
add_subdirectory(c)
set(primac_target "primac")
set(primac_target "primac;primafc")
endif ()

file (STRINGS VERSION.txt PRIMA_VERSION)
Expand Down
27 changes: 17 additions & 10 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
add_library (primac cintrf.f90 cobyla_c.f90 lincoa_c.f90 bobyqa_c.f90 newuoa_c.f90 uobyqa_c.f90 prima.c)

add_library (primafc cintrf.f90 cobyla_c.f90 lincoa_c.f90 bobyqa_c.f90 newuoa_c.f90 uobyqa_c.f90)
if (WIN32)
set_target_properties(primac PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
set_target_properties(primafc PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
target_link_libraries (primafc PUBLIC primaf) # must be PUBLIC for precision macros
set_target_properties(primafc PROPERTIES POSITION_INDEPENDENT_CODE ON)
if (NOT BUILD_SHARED_LIBS)
target_link_libraries (primafc INTERFACE ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
endif ()
# Export symbols on Windows. See more comments in fortran/CMakeLists.txt.
if (WIN32 AND BUILD_SHARED_LIBS)
target_sources(primafc PRIVATE primafc.def)
endif ()


add_library (primac prima.c)
if (WIN32)
set_target_properties(primac PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
endif()
target_include_directories (primac PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>)
target_link_libraries (primac PUBLIC primaf) # must be PUBLIC for precision macros
target_link_libraries (primac PRIVATE primafc)
set_target_properties(primac PROPERTIES POSITION_INDEPENDENT_CODE ON C_STANDARD 99)

if (NOT BUILD_SHARED_LIBS)
target_compile_definitions(primac PUBLIC PRIMAC_STATIC)
target_link_libraries (primac INTERFACE ${CMAKE_Fortran_IMPLICIT_LINK_LIBRARIES})
endif ()

# Export symbols on Windows. See more comments in fortran/CMakeLists.txt.
if (WIN32 AND BUILD_SHARED_LIBS)
target_sources(primac PRIVATE primac.def)
endif ()

install (FILES include/prima/prima.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/prima)
Expand Down
File renamed without changes.

0 comments on commit 94be275

Please sign in to comment.