From ed0ae66d5d2900f21a7219d7abc0eb895ab0f49a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luca=20Pep=C3=A8=20Sciarria?= Date: Thu, 5 Jun 2025 14:19:39 +0200 Subject: [PATCH] add CMakeLists.txt for test subprojects --- cbind/test/pdegen/CMakeLists.txt | 81 ++++++++++++++++++++++++++++++++ test/hello/CMakeLists.txt | 8 ++-- 2 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 cbind/test/pdegen/CMakeLists.txt diff --git a/cbind/test/pdegen/CMakeLists.txt b/cbind/test/pdegen/CMakeLists.txt new file mode 100644 index 00000000..788691fc --- /dev/null +++ b/cbind/test/pdegen/CMakeLists.txt @@ -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 $ ${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) diff --git a/test/hello/CMakeLists.txt b/test/hello/CMakeLists.txt index 70b0b04d..9c00e0d5 100644 --- a/test/hello/CMakeLists.txt +++ b/test/hello/CMakeLists.txt @@ -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}")