From f2f401c260eabcfaa9d4b03217a2477b8fe3262b Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Sat, 25 May 2024 11:08:34 +0200 Subject: [PATCH 1/3] move tests files a bit --- tests/CMakeLists.txt | 22 +++++++++++++++++++-- tests/{integration => }/c/CMakeLists.txt | 0 tests/{integration => }/c/test-c.c | 0 tests/{integration => }/cpp/TestCppLink.cpp | 0 4 files changed, 20 insertions(+), 2 deletions(-) rename tests/{integration => }/c/CMakeLists.txt (100%) rename tests/{integration => }/c/test-c.c (100%) rename tests/{integration => }/cpp/TestCppLink.cpp (100%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c1c6d27..253ed3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,25 @@ -add_executable(TestCppLink integration/cpp/TestCppLink.cpp) +add_executable(TestCppLink cpp/TestCppLink.cpp) target_link_libraries(TestCppLink sit) target_include_directories(TestCppLink PRIVATE ${SIT_API_INCLUDES}) + add_test(NAME TestCppLink - COMMAND TestCppLink) \ No newline at end of file + COMMAND TestCppLink) + + + +add_executable(TestFortranLink fortran/TestFortranModule.f90) +target_link_libraries(TestFortranLink sit sit_f) +target_include_directories(TestFortranLink + PRIVATE ${SIT_API_INCLUDES}) + +target_include_directories(TestFortranLink + PRIVATE ${CMAKE_BINARY_DIR}/include) + + + +add_test(NAME TestFortranLink + COMMAND TestFortranLink) + + \ No newline at end of file diff --git a/tests/integration/c/CMakeLists.txt b/tests/c/CMakeLists.txt similarity index 100% rename from tests/integration/c/CMakeLists.txt rename to tests/c/CMakeLists.txt diff --git a/tests/integration/c/test-c.c b/tests/c/test-c.c similarity index 100% rename from tests/integration/c/test-c.c rename to tests/c/test-c.c diff --git a/tests/integration/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp similarity index 100% rename from tests/integration/cpp/TestCppLink.cpp rename to tests/cpp/TestCppLink.cpp -- GitLab From aa5033576c65b38cf880dd3ab84b8adba05c1e8d Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Sat, 25 May 2024 11:08:56 +0200 Subject: [PATCH 2/3] Add fortran functionality --- CMakeLists.txt | 37 ++++++++++++++++++++++++++--- sit.yaml | 11 +++++++++ tests/fortran/TestFortranModule.f90 | 5 ++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 sit.yaml create mode 100644 tests/fortran/TestFortranModule.f90 diff --git a/CMakeLists.txt b/CMakeLists.txt index bed5335..fcb4dbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,12 +17,43 @@ set(SIT_API_INCLUDES ${PROJECT_SOURCE_DIR}/include) target_include_directories(sit PRIVATE ${SIT_API_INCLUDES}) -include(GenerateExportHeader) -generate_export_header(sit) +add_subdirectory(src) + +if(EXISTS ${SHROUD_EXECUTABLE}) + execute_process(COMMAND ${SHROUD_EXECUTABLE} + --cmake ${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake + ERROR_VARIABLE SHROUD_cmake_error + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(${SHROUD_cmake_error}) + message(FATAL_ERROR "Error from Shroud: ${SHROUD_cmake_error}") + endif() + include(${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake) + add_shroud( + YAML_INPUT_FILE sit.yaml + C_FORTRAN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} + ) + + set_source_files_properties(wrap${_basename}.cpp PROPERTIES GENERATED TRUE) + set_source_files_properties(wrapf${_basename}.f PROPERTIES GENERATED TRUE) + set(CMAKE_Fortran_FORMAT FREE) + + + + add_library(${_basename}_f STATIC wrapf${_basename}.f wrap${_basename}.cpp ${LIB_SRC}) + + target_include_directories(${_basename}_f PRIVATE ${SIT_API_INCLUDES}) + target_include_directories(${_basename}_f PRIVATE ${LIB_INC}) + + set_target_properties(${_basename}_f PROPERTIES LINKER_LANGUAGE Fortran) + set_target_properties(${_basename}_f PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set_target_properties(${_basename}_f PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) + + add_dependencies(${_basename}_f generate_${_basename}) +endif() + -add_subdirectory(src) enable_testing() diff --git a/sit.yaml b/sit.yaml new file mode 100644 index 0000000..67af98d --- /dev/null +++ b/sit.yaml @@ -0,0 +1,11 @@ +library: sit +namespace: sit +cxx_header: sit.hpp +format: + C_prefix: '' + +declarations: +- decl: void init(const std::string &backend) +- decl: void region_start(const std::string &name) +- decl: void region_stop(const std::string &name) +- decl: void finalize() \ No newline at end of file diff --git a/tests/fortran/TestFortranModule.f90 b/tests/fortran/TestFortranModule.f90 new file mode 100644 index 0000000..9194e19 --- /dev/null +++ b/tests/fortran/TestFortranModule.f90 @@ -0,0 +1,5 @@ +program do_sample + use sit_mod + call init("Default") + call region_start("test") +end program do_sample \ No newline at end of file -- GitLab From 9f7cbea6678fb100369742409b0ad1c1cfee9508 Mon Sep 17 00:00:00 2001 From: Valentin Seitz Date: Tue, 28 May 2024 15:46:34 +0200 Subject: [PATCH 3/3] A bit polluted commit; Did fortran stuff here too, but for the sake of fast and dirty: idc --- CMakeLists.txt | 110 ++++++++++++++++++++---------- README.md | 31 +++++++++ cmake/sitConfig.cmake | 1 + include/{ => sit}/sit.hpp | 0 src/CMakeLists.txt | 9 ++- src/bindings/CMakeLists.txt | 34 +++++++++ sit.yaml => src/bindings/sit.yaml | 4 +- src/sit.cpp | 2 +- test.cpp | 19 ++++++ tests/CMakeLists.txt | 37 ++++++---- tests/c/CMakeLists.txt | 10 --- tests/c/TestCLink.c | 3 + tests/c/test-c.c | 3 - tests/cpp/TestCppLink.cpp | 2 +- 14 files changed, 198 insertions(+), 67 deletions(-) create mode 100644 README.md create mode 100644 cmake/sitConfig.cmake rename include/{ => sit}/sit.hpp (100%) create mode 100644 src/bindings/CMakeLists.txt rename sit.yaml => src/bindings/sit.yaml (83%) create mode 100644 test.cpp delete mode 100644 tests/c/CMakeLists.txt create mode 100644 tests/c/TestCLink.c delete mode 100644 tests/c/test-c.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fcb4dbd..719edc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,50 +11,90 @@ list (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake") option(ENABLE_EXTRAE "Enable Extrae" OFF) option(ENABLE_DLB "Enable DLB" OFF) - +option(BUILD_C_FORTRAN "Enable C and Fortran Interfaces" ON) add_library(sit SHARED) -set(SIT_API_INCLUDES ${PROJECT_SOURCE_DIR}/include) -target_include_directories(sit PRIVATE ${SIT_API_INCLUDES}) + +set(SIT_PUBLIC_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include) + +target_include_directories(sit PUBLIC + $ + $ + $ + $ +) +#set_target_properties(sit PROPERTIES PUBLIC_HEADER "${SIT_PUBLIC_HEADERS}") + add_subdirectory(src) -if(EXISTS ${SHROUD_EXECUTABLE}) - execute_process(COMMAND ${SHROUD_EXECUTABLE} - --cmake ${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake - ERROR_VARIABLE SHROUD_cmake_error - OUTPUT_STRIP_TRAILING_WHITESPACE ) - if(${SHROUD_cmake_error}) - message(FATAL_ERROR "Error from Shroud: ${SHROUD_cmake_error}") - endif() - include(${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake) - add_shroud( - YAML_INPUT_FILE sit.yaml - C_FORTRAN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} - ) - - set_source_files_properties(wrap${_basename}.cpp PROPERTIES GENERATED TRUE) - set_source_files_properties(wrapf${_basename}.f PROPERTIES GENERATED TRUE) - set(CMAKE_Fortran_FORMAT FREE) - - - - add_library(${_basename}_f STATIC wrapf${_basename}.f wrap${_basename}.cpp ${LIB_SRC}) - - target_include_directories(${_basename}_f PRIVATE ${SIT_API_INCLUDES}) - target_include_directories(${_basename}_f PRIVATE ${LIB_INC}) - - set_target_properties(${_basename}_f PROPERTIES LINKER_LANGUAGE Fortran) - set_target_properties(${_basename}_f PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) - set_target_properties(${_basename}_f PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) - - add_dependencies(${_basename}_f generate_${_basename}) + +enable_testing() +add_subdirectory(tests) + + +# +# Install Targets for sit +# + +# Setup General Install for: +# precice - the library +include(GNUInstallDirs) +message(STATUS ${CMAKE_INSTALL_INCLUDEDIR}) + + + +if(BUILD_C_FORTRAN) + +install(TARGETS sit sit_f + EXPORT sitTargets + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sit + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sit + ) +else() + +install(TARGETS sit + EXPORT sitTargets + FILE_SET HEADERS + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sit + INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sit + ) +install(FILES ${SIT_PUBLIC_HEADERS}/sit/sit.hpp DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sit) endif() +# Export the Targets to install +install(EXPORT sitTargets + FILE sitTargets.cmake + NAMESPACE sit:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sit + ) +# Generate a Package Config File for precice +include(CMakePackageConfigHelpers) +write_basic_package_version_file("sitConfigVersion.cmake" + VERSION 1.0.0 + COMPATIBILITY SameMajorVersion + ) + +# Install the Config and the ConfigVersion files +install(FILES "cmake/sitConfig.cmake" "${sit_BINARY_DIR}/sitConfigVersion.cmake" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/sit + ) + +# Setup the config in the build directory +export(EXPORT sitTargets + NAMESPACE sit:: + FILE "sitTargets.cmake") +file(COPY "cmake/sitConfig.cmake" + DESTINATION "${sit_BINARY_DIR}") + +# Add an alias to allow subprojects to use the namespaced name +add_library(sit::sit ALIAS sit) -enable_testing() -add_subdirectory(tests) diff --git a/README.md b/README.md new file mode 100644 index 0000000..c13af42 --- /dev/null +++ b/README.md @@ -0,0 +1,31 @@ +# SIT? + +## CXX bindings + +How to configure and install: + +1. `cmake .. -DCMAKE_INSTALL_PREFIX= -DBUILD_C_FORTRAN=OFF` +2. `make install` + +### How to use + +```cpp +#include "sit/sit.hpp" + +int main() { + sit::init("Default"); + sit::region_start("peter"); + + sit::region_start("marie"); + + sit::region_stop("marie"); + + sit::region_stop("peter"); + sit::finalize(); +} + +You **must** call `sit::init` exactly once to init the datastructures before you can use the other functionality. +Also some backends require finalization, so please make sure to also call `finalize` in the end. + +To add it to your code, currently just install it and use something similar to: +`-I/include -L-I/lib -lsit` in the compiler options diff --git a/cmake/sitConfig.cmake b/cmake/sitConfig.cmake new file mode 100644 index 0000000..9423ad2 --- /dev/null +++ b/cmake/sitConfig.cmake @@ -0,0 +1 @@ +include("${CMAKE_CURRENT_LIST_DIR}/sitTargets.cmake") \ No newline at end of file diff --git a/include/sit.hpp b/include/sit/sit.hpp similarity index 100% rename from include/sit.hpp rename to include/sit/sit.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c84c72a..5825ab7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,7 @@ - add_subdirectory(backends) -target_include_directories(sit PRIVATE .) -target_sources(sit PRIVATE sit_delegator.cpp sit.cpp) \ No newline at end of file +target_sources(sit PRIVATE sit_delegator.cpp sit.cpp) + +if(BUILD_C_FORTRAN) + add_subdirectory(bindings) +endif() + diff --git a/src/bindings/CMakeLists.txt b/src/bindings/CMakeLists.txt new file mode 100644 index 0000000..69845ae --- /dev/null +++ b/src/bindings/CMakeLists.txt @@ -0,0 +1,34 @@ + +if(EXISTS ${SHROUD_EXECUTABLE}) + execute_process(COMMAND ${SHROUD_EXECUTABLE} + --cmake ${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake + ERROR_VARIABLE SHROUD_cmake_error + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(${SHROUD_cmake_error}) + message(FATAL_ERROR "Error from Shroud: ${SHROUD_cmake_error}") + endif() + include(${CMAKE_CURRENT_BINARY_DIR}/SetupShroud.cmake) + add_shroud( + YAML_INPUT_FILE sit.yaml + C_FORTRAN_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR} + ) + + set_source_files_properties(wrap${_basename}.cpp PROPERTIES GENERATED TRUE) + set_source_files_properties(wrapf${_basename}.f PROPERTIES GENERATED TRUE) + set(CMAKE_Fortran_FORMAT FREE) + list (APPEND SIT_PUBLIC_HEADERS "${LIB_INC}") + + + + add_library(${_basename}_f wrapf${_basename}.f wrap${_basename}.cpp ${LIB_SRC}) + + target_include_directories(${_basename}_f PRIVATE ${SIT_PUBLIC_HEADERS}) + + + set_target_properties(${_basename}_f PROPERTIES LINKER_LANGUAGE Fortran) + set_target_properties(${_basename}_f PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set_target_properties(${_basename}_f PROPERTIES Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include) + add_dependencies(${_basename}_f generate_${_basename}) +else() +message(FATAL_ERROR "Cannot build Fortran and C bindings without -DSHROUD_EXECUTABLE specified") +endif() diff --git a/sit.yaml b/src/bindings/sit.yaml similarity index 83% rename from sit.yaml rename to src/bindings/sit.yaml index 67af98d..1c7bf38 100644 --- a/sit.yaml +++ b/src/bindings/sit.yaml @@ -1,8 +1,8 @@ library: sit namespace: sit -cxx_header: sit.hpp +cxx_header: sit/sit.hpp format: - C_prefix: '' + C_prefix: 'sit_' declarations: - decl: void init(const std::string &backend) diff --git a/src/sit.cpp b/src/sit.cpp index 334c1d7..099c542 100644 --- a/src/sit.cpp +++ b/src/sit.cpp @@ -1,5 +1,5 @@ -#include "sit.hpp" +#include "sit/sit.hpp" #include "sit_delegator.hpp" #include namespace sit { diff --git a/test.cpp b/test.cpp new file mode 100644 index 0000000..0337b80 --- /dev/null +++ b/test.cpp @@ -0,0 +1,19 @@ +#include "sit/sit.hpp" + +int main() { + // Initialize the SIT library with a default configuration + sit::init("Default"); + + // Start a region named "Default" + sit::region_start("Default"); + + // Do some work here (for demonstration purposes, we won't do anything) + + // Stop the region named "Default" + sit::region_stop("Default"); + + // Finalize the SIT library + sit::finalize(); + + return 0; +} \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 253ed3a..279243e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,25 +1,38 @@ add_executable(TestCppLink cpp/TestCppLink.cpp) -target_link_libraries(TestCppLink sit) +target_link_libraries(TestCppLink sit::sit) target_include_directories(TestCppLink - PRIVATE ${SIT_API_INCLUDES}) + PRIVATE ${SIT_PUBLIC_HEADERS}) add_test(NAME TestCppLink COMMAND TestCppLink) +if(BUILD_C_FORTRAN) + add_executable(TestCLink c/TestCLink.c) + target_link_libraries(TestCLink sit) + target_include_directories(TestCLink + PRIVATE ${SIT_PUBLIC_HEADERS}) -add_executable(TestFortranLink fortran/TestFortranModule.f90) -target_link_libraries(TestFortranLink sit sit_f) -target_include_directories(TestFortranLink - PRIVATE ${SIT_API_INCLUDES}) -target_include_directories(TestFortranLink - PRIVATE ${CMAKE_BINARY_DIR}/include) - + add_test(NAME TestCLink + COMMAND TestCLink) -add_test(NAME TestFortranLink - COMMAND TestFortranLink) - \ No newline at end of file + + add_executable(TestFortranLink fortran/TestFortranModule.f90) + target_link_libraries(TestFortranLink sit sit_f) + target_include_directories(TestFortranLink + PRIVATE ${SIT_PUBLIC_HEADERS}) + + message(STATUS ${SIT_PUBLIC_HEADERS}) + + target_include_directories(TestFortranLink + PRIVATE ${CMAKE_BINARY_DIR}/include) + + + + add_test(NAME TestFortranLink + COMMAND TestFortranLink) +endif() \ No newline at end of file diff --git a/tests/c/CMakeLists.txt b/tests/c/CMakeLists.txt deleted file mode 100644 index 84d814c..0000000 --- a/tests/c/CMakeLists.txt +++ /dev/null @@ -1,10 +0,0 @@ -cmake_minimum_required (VERSION 3.22) -project(test-c VERSION 4.0.1 LANGUAGES C) - - -option(ENABLE_EXTRAE "Enable Extrae" OFF) -option(ENABLE_DLB "Enable DLB" OFF) - -add_executable(test-c) -find_package(sit REQUIRED) -target_link_libraries(test-c sit) diff --git a/tests/c/TestCLink.c b/tests/c/TestCLink.c new file mode 100644 index 0000000..1824f72 --- /dev/null +++ b/tests/c/TestCLink.c @@ -0,0 +1,3 @@ +//#include "wrapsit.h" + +int main() {} \ No newline at end of file diff --git a/tests/c/test-c.c b/tests/c/test-c.c deleted file mode 100644 index ace88c0..0000000 --- a/tests/c/test-c.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "sit.h" - -int main() {} \ No newline at end of file diff --git a/tests/cpp/TestCppLink.cpp b/tests/cpp/TestCppLink.cpp index 0c2e150..7f8baec 100644 --- a/tests/cpp/TestCppLink.cpp +++ b/tests/cpp/TestCppLink.cpp @@ -1,4 +1,4 @@ -#include "sit.hpp" +#include "sit/sit.hpp" int main() { sit::init("Default"); -- GitLab