add CMakeLists.txt for test subprojects

cmake
Luca Pepè Sciarria 11 months ago
parent b83ee77cd6
commit ed0ae66d5d

@ -0,0 +1,81 @@
cmake_minimum_required(VERSION 3.15)
project(PSB_PDEGen3D C)
# Project structure (mimicking Makefile's TOP)
set(TOP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../..") # Adjust if needed
# Include directories
include_directories(
"."
"${CMAKE_CURRENT_SOURCE_DIR}/../.."
"${TOP_DIR}/include"
)
# Fortran module directory
set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/modules")
set(FMFLAG "-I") # Adjust if needed
# Library directories
link_directories("${TOP_DIR}/lib")
# Libraries
set(PSBC_LIBS psb_cbind)
set(PSB_LIBS psb_util psb_linsolve psb_prec psb_base)
# Executable directory
set(EXEDIR "${CMAKE_CURRENT_BINARY_DIR}/runs")
file(MAKE_DIRECTORY "${EXEDIR}")
# Source files
set(SOURCE_FILES pdegen3dc.c)
# Create executable
add_executable(pdegen3dc ${SOURCE_FILES})
# Link libraries
target_link_libraries(pdegen3dc PUBLIC
${PSBC_LIBS}
${PSB_LIBS}
m # Math library
gfortran # gfortran library
)
# Move executable to EXEDIR (post-build)
add_custom_command(TARGET pdegen3dc POST_BUILD
COMMAND ${CMAKE_COMMAND} -E move $<TARGET_FILE:pdegen3dc> ${EXEDIR}
)
# 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
add_custom_target(verycleanlib
COMMAND ${CMAKE_COMMAND} -E chdir "../../" ${CMAKE_COMMAND} --build . --target veryclean
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Cleaning library"
)
# 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)

@ -2,10 +2,10 @@ cmake_minimum_required(VERSION 3.10)
project(HelloWorld Fortran)
# Accept a user-defined library path
set(LIBRARY_DIR "" CACHE PATH "Path to the library directory")
set(PSBLAS_INSTALL_DIR "" CACHE PATH "Path to the library directory")
# Check if the user provided a library directory
if(NOT LIBRARY_DIR)
if(NOT PSBLAS_INSTALL_DIR)
message(FATAL_ERROR "Library directory not specified! Use -DLIBRARY_DIR=path/to/library")
endif()
@ -13,7 +13,7 @@ endif()
include(CMakePackageConfigHelpers)
# Find the package
find_package(psblas REQUIRED PATHS ${LIBRARY_DIR}/lib/cmake/psblas NO_DEFAULT_PATH)
find_package(psblas REQUIRED PATHS ${PSBLAS_INSTALL_DIR}/lib/cmake/psblas NO_DEFAULT_PATH)
# Check if the package was found
if(NOT psblas_FOUND)
@ -21,7 +21,7 @@ if(NOT psblas_FOUND)
endif()
# Include directories for the library
include_directories(${LIBRARY_DIR}/include) # Path to header files
include_directories(${PSBLAS_INSTALL_DIR}/include) # Path to header files
include_directories(${psblas_DIR}/modules) # Path to module files
message(STATUS "Library directory: ${psblas_DIR}")

Loading…
Cancel
Save