cmake building now works

cmake
Luca Pepè Sciarria 12 months ago
parent 9c80208a33
commit c70ceb072c

@ -1,81 +1,44 @@
cmake_minimum_required(VERSION 3.15) cmake_minimum_required(VERSION 3.10)
project(PSB_PDEGen3D C) project(pdegen C Fortran)
# Project structure (mimicking Makefile's TOP) # Check for the installation path for psblas
set(TOP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") # Adjust if needed if(NOT DEFINED PSBLAS_INSTALL_DIR)
message(FATAL_ERROR "Please specify the path to the psblas installation directory using -DPSBLAS_INSTALL_DIR=<path>")
endif()
# Include directories # Set the include and library directories based on the provided path
include_directories( set(INSTALLDIR "${PSBLAS_INSTALL_DIR}")
"." set(INCDIR "${INSTALLDIR}/include")
"${CMAKE_CURRENT_SOURCE_DIR}/../.." set(MODDIR "${INSTALLDIR}/modules")
"${TOP_DIR}/include" set(LIBDIR "${INSTALLDIR}/lib")
)
# Fortran module directory #set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules")
set(FMFLAG "-I") # Adjust if needed
# Library directories # Find the psblas package
link_directories("${TOP_DIR}/lib") find_package(psblas REQUIRED PATHS ${INSTALLDIR})
# Libraries # Include directories for the Fortran compiler
set(PSBC_LIBS psb_cbind) include_directories(${INCDIR} ${MODDIR})
set(PSB_LIBS psb_util psb_linsolve psb_prec psb_base)
# Executable directory # Define executable directory
set(EXEDIR "${CMAKE_CURRENT_BINARY_DIR}/runs") set(EXEDIR "${CMAKE_CURRENT_SOURCE_DIR}/runs")
file(MAKE_DIRECTORY "${EXEDIR}")
# Source files # Ensure the executable directory exists
set(SOURCE_FILES pdegen3dc.c) file(MAKE_DIRECTORY ${EXEDIR})
# Create executable # Define sources for the executables
add_executable(pdegen3dc ${SOURCE_FILES}) set(SOURCES_PDEGEN pdegen3dc.c)
# Link libraries
target_link_libraries(pdegen3dc PUBLIC
${PSBC_LIBS}
${PSB_LIBS}
m # Math library
gfortran # gfortran library
)
# Move executable to EXEDIR (post-build) # Create executables
add_custom_command(TARGET pdegen3dc POST_BUILD add_executable(psb_pdegen ${SOURCES_PDEGEN})
COMMAND ${CMAKE_COMMAND} -E move $<TARGET_FILE:pdegen3dc> ${EXEDIR} target_link_libraries(psb_pdegen psblas::cbind psblas::ext psblas::util psblas::linsolve psblas::prec psblas::base )
)
# Create "runs" directory (if it doesn't exist)
add_custom_target(create_runs_dir
COMMAND ${CMAKE_COMMAND} -E make_directory "${EXEDIR}"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Creating runs directory"
)
add_dependencies(pdegen3dc create_runs_dir)
# verycleanlib target # Set output directory for executables
add_custom_target(verycleanlib foreach(target psb_pdegen)
COMMAND ${CMAKE_COMMAND} -E chdir "../../" ${CMAKE_COMMAND} --build . --target veryclean set_target_properties(${target} PROPERTIES
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} RUNTIME_OUTPUT_DIRECTORY ${EXEDIR}
COMMENT "Cleaning library" )
) endforeach()
# lib target
add_custom_target(lib
COMMAND ${CMAKE_COMMAND} -E chdir "../../" ${CMAKE_COMMAND} --build . --target library
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building library"
)
# tests target
add_custom_target(tests
COMMAND ${CMAKE_COMMAND} -E chdir "${EXEDIR}" ${CMAKE_CURRENT_SOURCE_DIR}/${EXEDIR}/pdegen3dc < ${CMAKE_CURRENT_SOURCE_DIR}/${EXEDIR}/pdegen3d.inp
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS pdegen3dc
COMMENT "Running tests"
)
add_dependencies(tests pdegen3dc)
# Install target (optional)
install(TARGETS pdegen3dc DESTINATION bin)

Loading…
Cancel
Save