Skip to content

Commit

Permalink
Merge pull request #135 from gruenich/feature/generate-fortran-config
Browse files Browse the repository at this point in the history
[cmake] Improve generating of superlu_config.fh
  • Loading branch information
xiaoyeli committed Dec 31, 2023
2 parents 76b2c9a + 5d1b075 commit f24a800
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 26 deletions.
34 changes: 17 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ if (TPL_METIS_INCLUDE_DIRS)
include_directories(${TPL_METIS_INCLUDE_DIRS}) ## metis
endif ()

# Generate various configure files with proper definitions

# file(WRITE "make.defs" "# can be exposed to users"
# ${CMAKE_C_COMPILER} )
# configure_file(${CMAKE_SOURCE_DIR}/make.inc.in ${CMAKE_SOURCE_DIR}/make.inc)
configure_file(${SuperLU_SOURCE_DIR}/make.inc.in ${SuperLU_SOURCE_DIR}/make.inc)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/superlu.pc.in ${CMAKE_CURRENT_BINARY_DIR}/superlu.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/superlu.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_BINARY_DIR}/SRC/superlu_config.h)
configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_SOURCE_DIR}/SRC/superlu_config.h)

# Following is to configure a header file for FORTRAN code
configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_BINARY_DIR}/FORTRAN/superlu_config.h)

######################################################################
#
# Add subdirectories
Expand Down Expand Up @@ -240,20 +257,3 @@ add_subdirectory(EXAMPLE)
if (enable_doc)
add_subdirectory(DOC)
endif()

# Generate various configure files with proper definitions

# file(WRITE "make.defs" "# can be exposed to users"
# ${CMAKE_C_COMPILER} )
# configure_file(${CMAKE_SOURCE_DIR}/make.inc.in ${CMAKE_SOURCE_DIR}/make.inc)
configure_file(${SuperLU_SOURCE_DIR}/make.inc.in ${SuperLU_SOURCE_DIR}/make.inc)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/superlu.pc.in ${CMAKE_CURRENT_BINARY_DIR}/superlu.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/superlu.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_BINARY_DIR}/SRC/superlu_config.h)
configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_SOURCE_DIR}/SRC/superlu_config.h)

# Following is to configure a header file for FORTRAN code
configure_file(${SuperLU_SOURCE_DIR}/SRC/superlu_config.h.in ${SuperLU_BINARY_DIR}/FORTRAN/superlu_config.h)
15 changes: 6 additions & 9 deletions FORTRAN/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ set_target_properties(superlu_fortran-static PROPERTIES SOVERSION ${superlu_sove
target_link_libraries(superlu_fortran-static superlu)

# depends on FPP defs
add_dependencies(superlu_fortran config_f)
add_dependencies(superlu_fortran-static config_f)
add_dependencies(superlu_fortran-static superlu_fortran)

install(TARGETS superlu_fortran
Expand Down Expand Up @@ -91,10 +89,9 @@ if(enable_examples)
endif() # enable_example

# Format superlu_config.fh from superlu_config.h in C
add_custom_command(
OUTPUT ${CMAKE_BINARY_DIR}/FORTRAN/superlu_config.fh
COMMAND sed;'s/\\/.*$$//';<;superlu_config.h;>;temp.fh
COMMAND sed;'/typedef/;d';<;temp.fh;>;superlu_config.fh
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/FORTRAN
)
add_custom_target(config_f DEPENDS ${CMAKE_BINARY_DIR}/FORTRAN/superlu_config.fh)
file(READ "${CMAKE_BINARY_DIR}/SRC/superlu_config.h" CONFIG_FILE_H)
# remove C comments /* */
string(REGEX REPLACE "/\\*[^(\\*/)]*\\*/" " " CONFIG_FILE_H_NO_COMMENTS "${CONFIG_FILE_H}")
# remove typedefs
string(REGEX REPLACE "typedef[^;]*;" " " CONFIG_FILE_FH "${CONFIG_FILE_H_NO_COMMENTS}")
file(WRITE "${CMAKE_BINARY_DIR}/FORTRAN/superlu_config.fh" "${CONFIG_FILE_FH}")

0 comments on commit f24a800

Please sign in to comment.