From b84a0ef6f91fd5ca4797c64049ffff86a2903a1d Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 29 Sep 2023 19:20:29 +0200 Subject: [PATCH 01/20] give path to init.c depending on build.jl path --- LibTrixi.jl/lib/build.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LibTrixi.jl/lib/build.jl b/LibTrixi.jl/lib/build.jl index 9c07eb15..f3b61bf8 100644 --- a/LibTrixi.jl/lib/build.jl +++ b/LibTrixi.jl/lib/build.jl @@ -54,7 +54,7 @@ header_files = [joinpath(dirname(dirname(@__DIR__)), "src", "trixi.h")] # Name of the files that include the initialization functions: # - `init.c` contains `trixi_initialize`/`trixi_finalize` for API compatibility # - the other file contains the `init_julia`/`shutdown_julia` functions from PackageCompiler -julia_init_c_file = ["init.c", PackageCompiler.default_julia_init()] +julia_init_c_file = [joinpath(@__DIR__, "init.c"), PackageCompiler.default_julia_init()] # Extract version from `Project.toml` project_toml = joinpath(package_or_project_dir, "Project.toml") From 0203687cadd493b7a93d107c5c6f4975f91732e0 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 29 Sep 2023 19:21:59 +0200 Subject: [PATCH 02/20] introduce option to use PackageCompiler - required JULIA_PROJECT_PATH (so does testing) - install missing - examples missing --- CMakeLists.txt | 122 ++++++++++++++++++++++++++++--------------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea99197c..3cadedc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,74 +60,92 @@ if( ENABLE_TESTING ) find_package( test-drive REQUIRED ) endif() +# Optionally use PackageCompiler.jl to build standalone libtrixi.so +option( USE_PACKAGE_COMPILER "Build standalone libtrixi.so using PackageCompiler.jl" ) +if( USE_PACKAGE_COMPILER ) + if ( NOT DEFINED JULIA_PROJECT_PATH ) + message( FATAL_ERROR "JULIA_PROJECT_PATH needs to be set for PackageCompiler.jl.") + endif() + # no sources + add_library( ${PROJECT_NAME} INTERFACE build-pc/lib/libtrixi.so ) + add_custom_command( OUTPUT build-pc/lib/libtrixi.so + COMMENT "Building ${PROJECT_NAME} with PackageCompiler.jl..." + COMMAND ${JULIA_EXECUTABLE} + --project=${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib + ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/build.jl + ${JULIA_PROJECT_PATH} + ${CMAKE_BINARY_DIR}/build-pc ) -# Library target -add_library ( ${PROJECT_NAME} SHARED - src/api.c - src/api.f90 - src/auxiliary.h - src/auxiliary.c - src/trixi.h -) +else() -# Include directories, private -target_include_directories ( ${PROJECT_NAME} PRIVATE src ) + # Library target + add_library ( ${PROJECT_NAME} SHARED + src/api.c + src/api.f90 + src/auxiliary.h + src/auxiliary.c + src/trixi.h + ) -# Version info -set_target_properties ( ${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} ) + # Include directories, private + target_include_directories ( ${PROJECT_NAME} PRIVATE src ) -# Version info for the shared object -set_target_properties ( ${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) + # Version info + set_target_properties ( ${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} ) -# Include directories, public for actual users -set_target_properties ( ${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/trixi.h ) + # Version info for the shared object + set_target_properties ( ${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) -# Fortran mod file location -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) + # Include directories, public for actual users + set_target_properties ( ${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/trixi.h ) + # Fortran mod file location + set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) -# Include directories -target_include_directories( ${PROJECT_NAME} PRIVATE src ${JULIA_INCLUDE_DIRS} ) -if ( T8CODE_FOUND ) - target_include_directories( ${PROJECT_NAME} PRIVATE ${T8CODE_INCLUDE_DIR} ) -endif() -# Libraries to link -target_link_libraries( ${PROJECT_NAME} PRIVATE ${JULIA_LIBRARY} ) + # Include directories + target_include_directories( ${PROJECT_NAME} PRIVATE src ${JULIA_INCLUDE_DIRS} ) + if ( T8CODE_FOUND ) + target_include_directories( ${PROJECT_NAME} PRIVATE ${T8CODE_INCLUDE_DIR} ) + endif() + + # Libraries to link + target_link_libraries( ${PROJECT_NAME} PRIVATE ${JULIA_LIBRARY} ) -# Set appropriate compile flags -target_compile_options( ${PROJECT_NAME} PUBLIC "-fPIC" ) -target_compile_options( ${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) -# Require C11 standard with GNU extensions for C files -target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-std=gnu11>) -# Require Fortran 2018 standard for Fortran files -target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-std=f2018>) + # Set appropriate compile flags + target_compile_options( ${PROJECT_NAME} PUBLIC "-fPIC" ) + target_compile_options( ${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) + # Require C11 standard with GNU extensions for C files + target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-std=gnu11>) + # Require Fortran 2018 standard for Fortran files + target_compile_options( ${PROJECT_NAME} PRIVATE $<$:-std=f2018>) -# Add auxiliary *object* library to support fast thread-local storage (TLS) -add_library ( ${PROJECT_NAME}_tls OBJECT - src/tls.c -) -target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} ) + # Add auxiliary *object* library to support fast thread-local storage (TLS) + add_library ( ${PROJECT_NAME}_tls OBJECT + src/tls.c + ) + target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} ) -# Add examples -add_subdirectory( examples ) + # Add examples + add_subdirectory( examples ) -# Add test on demand -if( ENABLE_TESTING ) - enable_testing() - add_subdirectory( test/c ) - add_subdirectory( test/fortran ) -endif() + # Add test on demand + if( ENABLE_TESTING ) + enable_testing() + add_subdirectory( test/c ) + add_subdirectory( test/fortran ) + endif() -# Install configuration -install( TARGETS ${PROJECT_NAME} ) -install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE) -install( FILES $ TYPE LIB RENAME lib${PROJECT_NAME}_tls.o ) -install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi ) -install( FILES "${CMAKE_BINARY_DIR}/LIBTRIXI_VERSION" DESTINATION share/julia ) -install( PROGRAMS utils/libtrixi-init-julia TYPE BIN ) + # Install configuration + install( TARGETS ${PROJECT_NAME} ) + install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE) + install( FILES $ TYPE LIB RENAME lib${PROJECT_NAME}_tls.o ) + install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi ) + install( FILES "${CMAKE_BINARY_DIR}/LIBTRIXI_VERSION" DESTINATION share/julia ) + install( PROGRAMS utils/libtrixi-init-julia TYPE BIN ) +endif() From 7c093a25c9dde47bb8ce3cc093fa384ff241c26e Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 2 Oct 2023 11:27:20 +0200 Subject: [PATCH 03/20] copy init.c to build tree s.t. no init.o will end up in the source tree --- CMakeLists.txt | 12 +++++++++--- LibTrixi.jl/lib/build.jl | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cadedc1..25a8238c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,15 +67,21 @@ if( USE_PACKAGE_COMPILER ) message( FATAL_ERROR "JULIA_PROJECT_PATH needs to be set for PackageCompiler.jl.") endif() + # copy source with initialization routines, an object file will be created + file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) + file( COPY_FILE ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c + ${CMAKE_BINARY_DIR}/build-pc/init.c + ONLY_IF_DIFFERENT ) # no sources - add_library( ${PROJECT_NAME} INTERFACE build-pc/lib/libtrixi.so ) - add_custom_command( OUTPUT build-pc/lib/libtrixi.so + add_library( ${PROJECT_NAME} INTERFACE prefix-pc/lib/libtrixi.so ) + add_custom_command( OUTPUT prefix-pc/lib/libtrixi.so COMMENT "Building ${PROJECT_NAME} with PackageCompiler.jl..." COMMAND ${JULIA_EXECUTABLE} --project=${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/build.jl ${JULIA_PROJECT_PATH} - ${CMAKE_BINARY_DIR}/build-pc ) + ${CMAKE_BINARY_DIR}/prefix-pc + WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) else() diff --git a/LibTrixi.jl/lib/build.jl b/LibTrixi.jl/lib/build.jl index f3b61bf8..9c07eb15 100644 --- a/LibTrixi.jl/lib/build.jl +++ b/LibTrixi.jl/lib/build.jl @@ -54,7 +54,7 @@ header_files = [joinpath(dirname(dirname(@__DIR__)), "src", "trixi.h")] # Name of the files that include the initialization functions: # - `init.c` contains `trixi_initialize`/`trixi_finalize` for API compatibility # - the other file contains the `init_julia`/`shutdown_julia` functions from PackageCompiler -julia_init_c_file = [joinpath(@__DIR__, "init.c"), PackageCompiler.default_julia_init()] +julia_init_c_file = ["init.c", PackageCompiler.default_julia_init()] # Extract version from `Project.toml` project_toml = joinpath(package_or_project_dir, "Project.toml") From 684c00d807c146a49e408faa19c0d9608b75fe05 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 2 Oct 2023 11:33:16 +0200 Subject: [PATCH 04/20] rename JULIA_PROJECT_PATH to LIBTRIXI_JULIA_PROJECT --- .github/workflows/ci.yml | 4 ++-- CMakeLists.txt | 12 ++++++------ docs/src/developers.md | 2 +- test/c/CMakeLists.txt | 2 +- test/c/auxiliary.cpp | 2 +- test/c/interface_c.cpp | 2 +- test/c/simulation.cpp | 2 +- test/c/t8code.cpp | 2 +- test/fortran/CMakeLists.txt | 2 +- test/fortran/juliaCode_suite.f90 | 2 +- test/fortran/simulationRun_suite.f90 | 2 +- test/fortran/versionInfo_suite.f90 | 2 +- 12 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c662b44c..6bb35832 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: cmake .. -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_BUILD_TYPE=Release \ -DT8CODE_PREFIX=$PWD/../t8code-local/prefix \ - -DENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia + -DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia - name: Configure (test_type == 'coverage') if: ${{ matrix.test_type == 'coverage' }} @@ -113,7 +113,7 @@ jobs: -DCMAKE_Fortran_FLAGS="-cpp --coverage -O0" \ -DCMAKE_EXE_LINKER_FLAGS="--coverage" \ -DCMAKE_SHARED_LINKER_FLAGS="--coverage" \ - -DENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia + -DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia - name: Build if: ${{ matrix.test_type == 'regular' || matrix.test_type == 'coverage' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index 25a8238c..b3171705 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,10 +47,10 @@ find_package( MPI REQUIRED ) # Find Google Test and test-drive on demand option( ENABLE_TESTING "Build tests using Google Test (C) and test-drive (Fortran)" ) if( ENABLE_TESTING ) - if ( NOT DEFINED JULIA_PROJECT_PATH ) - message( FATAL_ERROR "JULIA_PROJECT_PATH not set, tests will not work.") + if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) + message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT not set, tests will not work.") endif() - set( JULIA_PROJECT_PATH ${JULIA_PROJECT_PATH} CACHE PATH + set( LIBTRIXI_JULIA_PROJECT ${LIBTRIXI_JULIA_PROJECT} CACHE PATH "Path to Julia project (typically 'libtrixi-julia').") find_package( GTest REQUIRED ) @@ -63,8 +63,8 @@ endif() # Optionally use PackageCompiler.jl to build standalone libtrixi.so option( USE_PACKAGE_COMPILER "Build standalone libtrixi.so using PackageCompiler.jl" ) if( USE_PACKAGE_COMPILER ) - if ( NOT DEFINED JULIA_PROJECT_PATH ) - message( FATAL_ERROR "JULIA_PROJECT_PATH needs to be set for PackageCompiler.jl.") + if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) + message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT needs to be set for PackageCompiler.jl.") endif() # copy source with initialization routines, an object file will be created @@ -79,7 +79,7 @@ if( USE_PACKAGE_COMPILER ) COMMAND ${JULIA_EXECUTABLE} --project=${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/build.jl - ${JULIA_PROJECT_PATH} + ${LIBTRIXI_JULIA_PROJECT} ${CMAKE_BINARY_DIR}/prefix-pc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) diff --git a/docs/src/developers.md b/docs/src/developers.md index 0ead48c8..d148ed1f 100644 --- a/docs/src/developers.md +++ b/docs/src/developers.md @@ -50,7 +50,7 @@ For testing the C interface of libtrixi we rely on [GoogleTest](https://google.g The tests are contained in `cpp`-files located under `test/c`. They are processed by `cmake` and made available via `ctest`, provided the options ``` --DENABLE_TESTING=ON -DJULIA_PROJECT_PATH= +-DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT= ``` are passed to `cmake` during configuration. The executables can then be found under `/test/c` (they will not be installed). To run them, execute diff --git a/test/c/CMakeLists.txt b/test/c/CMakeLists.txt index 4ecc3202..ab4f3d89 100644 --- a/test/c/CMakeLists.txt +++ b/test/c/CMakeLists.txt @@ -40,7 +40,7 @@ foreach ( TEST ${TESTS} ) # pass julia project path target_compile_definitions( ${TARGET_NAME} PRIVATE - JULIA_PROJECT_PATH=\"${JULIA_PROJECT_PATH}\" ) + LIBTRIXI_JULIA_PROJECT=\"${LIBTRIXI_JULIA_PROJECT}\" ) # discover tests gtest_discover_tests( ${TARGET_NAME} ) diff --git a/test/c/auxiliary.cpp b/test/c/auxiliary.cpp index fa1dd101..a69e956c 100644 --- a/test/c/auxiliary.cpp +++ b/test/c/auxiliary.cpp @@ -6,7 +6,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = JULIA_PROJECT_PATH; +const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; const char* default_depot_path = "julia-depot"; diff --git a/test/c/interface_c.cpp b/test/c/interface_c.cpp index a625e6c5..0d5b446c 100644 --- a/test/c/interface_c.cpp +++ b/test/c/interface_c.cpp @@ -7,7 +7,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = JULIA_PROJECT_PATH; +const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; // Example libexlixir const char * libelixir_path = diff --git a/test/c/simulation.cpp b/test/c/simulation.cpp index 0db32dc5..aa7de3af 100644 --- a/test/c/simulation.cpp +++ b/test/c/simulation.cpp @@ -6,7 +6,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = JULIA_PROJECT_PATH; +const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; // Example libexlixir const char * libelixir_path = diff --git a/test/c/t8code.cpp b/test/c/t8code.cpp index b6bc8afe..d15db3e3 100644 --- a/test/c/t8code.cpp +++ b/test/c/t8code.cpp @@ -5,7 +5,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = JULIA_PROJECT_PATH; +const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; // Example libexlixir const char * libelixir_path = diff --git a/test/fortran/CMakeLists.txt b/test/fortran/CMakeLists.txt index 115cbee9..c4ac55c5 100644 --- a/test/fortran/CMakeLists.txt +++ b/test/fortran/CMakeLists.txt @@ -32,7 +32,7 @@ target_compile_options( ${TARGET_NAME} PRIVATE -cpp -Wall -Wextra -Werror -Wno-u # pass julia project path target_compile_definitions( ${TARGET_NAME} PRIVATE - JULIA_PROJECT_PATH=\"${JULIA_PROJECT_PATH}\" ) + LIBTRIXI_JULIA_PROJECT=\"${LIBTRIXI_JULIA_PROJECT}\" ) # add tests foreach ( TEST ${TESTS} ) diff --git a/test/fortran/juliaCode_suite.f90 b/test/fortran/juliaCode_suite.f90 index 7e28492a..507755b4 100644 --- a/test/fortran/juliaCode_suite.f90 +++ b/test/fortran/juliaCode_suite.f90 @@ -6,7 +6,7 @@ module juliaCode_suite public :: collect_juliaCode_suite - character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH + character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT contains diff --git a/test/fortran/simulationRun_suite.f90 b/test/fortran/simulationRun_suite.f90 index 1f81eb6f..0907f463 100644 --- a/test/fortran/simulationRun_suite.f90 +++ b/test/fortran/simulationRun_suite.f90 @@ -6,7 +6,7 @@ module simulationRun_suite public :: collect_simulationRun_suite - character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH + character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT character(len=*), parameter, public :: libelixir_path = & "../../../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl" diff --git a/test/fortran/versionInfo_suite.f90 b/test/fortran/versionInfo_suite.f90 index eb1cc88d..c20ef477 100644 --- a/test/fortran/versionInfo_suite.f90 +++ b/test/fortran/versionInfo_suite.f90 @@ -7,7 +7,7 @@ module versionInfo_suite public :: collect_versionInfo_suite - character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH + character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT contains From 9ddb0d335b62cb15f2297914d05f24bb6f2c4c0f Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 2 Oct 2023 16:36:18 +0200 Subject: [PATCH 05/20] compile examples when using PackageCompiler - also add Fortran module --- CMakeLists.txt | 47 ++++++++++++++++++++++++++--------------- examples/CMakeLists.txt | 8 ++++++- 2 files changed, 37 insertions(+), 18 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b3171705..926c68e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,25 +56,37 @@ if( ENABLE_TESTING ) find_package( GTest REQUIRED ) set ( TEST_DRIVE_FIND_METHOD fetch ) - # option TEST_DRIVE_BUILD_TESTING is hard-coded to ON + # Option TEST_DRIVE_BUILD_TESTING is hard-coded to ON, could be spared find_package( test-drive REQUIRED ) endif() # Optionally use PackageCompiler.jl to build standalone libtrixi.so option( USE_PACKAGE_COMPILER "Build standalone libtrixi.so using PackageCompiler.jl" ) + if( USE_PACKAGE_COMPILER ) if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT needs to be set for PackageCompiler.jl.") endif() - # copy source with initialization routines, an object file will be created + # Copy source with initialization routines; an object file will be created file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) file( COPY_FILE ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c ${CMAKE_BINARY_DIR}/build-pc/init.c ONLY_IF_DIFFERENT ) - # no sources - add_library( ${PROJECT_NAME} INTERFACE prefix-pc/lib/libtrixi.so ) - add_custom_command( OUTPUT prefix-pc/lib/libtrixi.so + + # Define PackageCompiler.jl output file + set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) + + # Add a library target (libtrixi), but only for Fortran module) + add_library( ${PROJECT_NAME} SHARED + src/api.f90 + ) + + # Add linking to the real libtrixi.so produced by PackageCompiler.jl + target_link_libraries( ${PROJECT_NAME} INTERFACE ${PC_LIBTRIXI_SO} ) + + # Actual command to run PackageCompiler.jl + add_custom_command( OUTPUT ${PC_LIBTRIXI_SO} COMMENT "Building ${PROJECT_NAME} with PackageCompiler.jl..." COMMAND ${JULIA_EXECUTABLE} --project=${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib @@ -82,9 +94,7 @@ if( USE_PACKAGE_COMPILER ) ${LIBTRIXI_JULIA_PROJECT} ${CMAKE_BINARY_DIR}/prefix-pc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) - else() - # Library target add_library ( ${PROJECT_NAME} SHARED src/api.c @@ -106,9 +116,6 @@ else() # Include directories, public for actual users set_target_properties ( ${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/trixi.h ) - # Fortran mod file location - set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) - # Include directories @@ -136,9 +143,6 @@ else() ) target_include_directories( ${PROJECT_NAME}_tls PRIVATE ${JULIA_INCLUDE_DIRS} ) - # Add examples - add_subdirectory( examples ) - # Add test on demand if( ENABLE_TESTING ) enable_testing() @@ -148,10 +152,19 @@ else() # Install configuration - install( TARGETS ${PROJECT_NAME} ) - install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE) install( FILES $ TYPE LIB RENAME lib${PROJECT_NAME}_tls.o ) - install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi ) install( FILES "${CMAKE_BINARY_DIR}/LIBTRIXI_VERSION" DESTINATION share/julia ) - install( PROGRAMS utils/libtrixi-init-julia TYPE BIN ) endif() + + +# Fortran mod file location +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) + +# Common install configuration +install( TARGETS ${PROJECT_NAME} ) +install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi ) +install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE) +install( PROGRAMS utils/libtrixi-init-julia TYPE BIN ) + +# Add examples +add_subdirectory( examples ) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index b1c8ff39..7b6c899a 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -31,8 +31,11 @@ foreach ( EXAMPLE ${EXAMPLES} ) # set libraries to link target_link_libraries( ${TARGET_NAME} - PRIVATE MPI::MPI_${EXAMPLE_LANG} ${PROJECT_NAME} ${PROJECT_NAME}_tls + PRIVATE MPI::MPI_${EXAMPLE_LANG} ${PROJECT_NAME} ) + if ( NOT USE_PACKAGE_COMPILER ) + target_link_libraries( ${TARGET_NAME} PRIVATE ${PROJECT_NAME}_tls ) + endif() if ( T8CODE_FOUND ) target_link_libraries( ${TARGET_NAME} PRIVATE ${T8CODE_LIBRARIES} ) endif() @@ -52,6 +55,9 @@ foreach ( EXAMPLE ${EXAMPLES} ) PROPERTIES INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib" ) + # position independent code + target_compile_options( ${TARGET_NAME} PRIVATE "-fPIC" ) + # enable warnings target_compile_options( ${TARGET_NAME} PRIVATE -Wall -Wextra -Werror ) From 8e53bcecb50eae5e2d851b3b65c56dcc56bacbd3 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 2 Oct 2023 17:39:26 +0200 Subject: [PATCH 06/20] make installation work when using PackageCompiler --- CMakeLists.txt | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 926c68e6..3a2e0298 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,6 +63,9 @@ endif() # Optionally use PackageCompiler.jl to build standalone libtrixi.so option( USE_PACKAGE_COMPILER "Build standalone libtrixi.so using PackageCompiler.jl" ) +# Fortran mod file location +set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) + if( USE_PACKAGE_COMPILER ) if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT needs to be set for PackageCompiler.jl.") @@ -77,8 +80,8 @@ if( USE_PACKAGE_COMPILER ) # Define PackageCompiler.jl output file set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) - # Add a library target (libtrixi), but only for Fortran module) - add_library( ${PROJECT_NAME} SHARED + # Add a library target (libtrixi), but only for Fortran module + add_library( ${PROJECT_NAME} OBJECT src/api.f90 ) @@ -94,6 +97,12 @@ if( USE_PACKAGE_COMPILER ) ${LIBTRIXI_JULIA_PROJECT} ${CMAKE_BINARY_DIR}/prefix-pc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) + + # Install configuration + install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/lib/" TYPE LIB ) + install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/share/julia" + DESTINATION share + PATTERN "cert.pem" EXCLUDE ) else() # Library target add_library ( ${PROJECT_NAME} SHARED @@ -113,9 +122,6 @@ else() # Version info for the shared object set_target_properties ( ${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} ) - # Include directories, public for actual users - set_target_properties ( ${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/trixi.h ) - # Include directories @@ -157,12 +163,13 @@ else() endif() -# Fortran mod file location -set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) + +# Public header for libtrixi +set_target_properties ( ${PROJECT_NAME} PROPERTIES PUBLIC_HEADER src/trixi.h ) # Common install configuration install( TARGETS ${PROJECT_NAME} ) -install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi ) +install( DIRECTORY LibTrixi.jl DESTINATION share/libtrixi PATTERN "lib" EXCLUDE ) install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE) install( PROGRAMS utils/libtrixi-init-julia TYPE BIN ) From 63f0ab20010a07bf236e58c4d45c2cf5f9d77688 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Mon, 2 Oct 2023 17:42:16 +0200 Subject: [PATCH 07/20] fix build type in docs --- README.md | 2 +- docs/src/index.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 03b51ff4..031e3cc7 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ For building, `cmake` and its typical workflow is used. 2. Call cmake ```bash - cmake -DCMAKE_BUILD_TYPE=(debug|release) -DCMAKE_INSTALL_PREFIX= .. + cmake -DCMAKE_BUILD_TYPE=(Debug|Release) -DCMAKE_INSTALL_PREFIX= .. ``` `cmake` should find `MPI` and `Julia` automatically. If not, the directories diff --git a/docs/src/index.md b/docs/src/index.md index b03fb759..8c0ee384 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -49,7 +49,7 @@ For building, `cmake` and its typical workflow is used. 2. Call cmake ```bash - cmake -DCMAKE_BUILD_TYPE=(debug|release) -DCMAKE_INSTALL_PREFIX= .. + cmake -DCMAKE_BUILD_TYPE=(Debug|Release) -DCMAKE_INSTALL_PREFIX= .. ``` `cmake` should find `MPI` and `Julia` automatically. If not, the directories From 148d109e39ac0bf97cdc63018a31b0c60d4a648a Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 4 Oct 2023 13:24:17 +0200 Subject: [PATCH 08/20] add libtrixi.so to sources apparently necessary s.t. a rule for building libtrixi.so is generated --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a2e0298..9d8be749 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -80,15 +80,18 @@ if( USE_PACKAGE_COMPILER ) # Define PackageCompiler.jl output file set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) - # Add a library target (libtrixi), but only for Fortran module + # Add a library target (libtrixi) + # - for Fortran module (therefore OBJECT library) + # - for generating a rule to build libtrixi.so add_library( ${PROJECT_NAME} OBJECT src/api.f90 + ${PC_LIBTRIXI_SO} ) # Add linking to the real libtrixi.so produced by PackageCompiler.jl target_link_libraries( ${PROJECT_NAME} INTERFACE ${PC_LIBTRIXI_SO} ) - # Actual command to run PackageCompiler.jl + # Command to run PackageCompiler.jl to actually produce libtrixi.so add_custom_command( OUTPUT ${PC_LIBTRIXI_SO} COMMENT "Building ${PROJECT_NAME} with PackageCompiler.jl..." COMMAND ${JULIA_EXECUTABLE} From e22e4d73b288a70145ef1e89548fb5cfc26c2015 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 4 Oct 2023 13:59:51 +0200 Subject: [PATCH 09/20] warn about unsupported testing when using PackageCompiler --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d8be749..195981d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,9 @@ if( USE_PACKAGE_COMPILER ) if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT needs to be set for PackageCompiler.jl.") endif() + if ( ENABLE_TESTING ) + message( NOTICE "Testing is not supported when PackageCompiler is used.") + endif() # Copy source with initialization routines; an object file will be created file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) From 07b17d9ede8fbd9561a41a3b3e8400420fac7775 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 14:39:14 +0200 Subject: [PATCH 10/20] revise cmake script using add_custom_target --- CMakeLists.txt | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 195981d7..c2cd831d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -83,18 +83,12 @@ if( USE_PACKAGE_COMPILER ) # Define PackageCompiler.jl output file set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) - # Add a library target (libtrixi) - # - for Fortran module (therefore OBJECT library) - # - for generating a rule to build libtrixi.so + # Add a library target (libtrixi), only for Fortran module add_library( ${PROJECT_NAME} OBJECT src/api.f90 - ${PC_LIBTRIXI_SO} ) - # Add linking to the real libtrixi.so produced by PackageCompiler.jl - target_link_libraries( ${PROJECT_NAME} INTERFACE ${PC_LIBTRIXI_SO} ) - - # Command to run PackageCompiler.jl to actually produce libtrixi.so + # Custom command to run PackageCompiler.jl to produce libtrixi.so add_custom_command( OUTPUT ${PC_LIBTRIXI_SO} COMMENT "Building ${PROJECT_NAME} with PackageCompiler.jl..." COMMAND ${JULIA_EXECUTABLE} @@ -104,6 +98,15 @@ if( USE_PACKAGE_COMPILER ) ${CMAKE_BINARY_DIR}/prefix-pc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) + # Custom target for PackageCompiler.jl's libtrixi.so + add_custom_target( PC_LIBTRIXI DEPENDS ${PC_LIBTRIXI_SO} ) + + # Depency of main library target on PackageCompiler.jl target + add_dependencies( ${PROJECT_NAME} PC_LIBTRIXI ) + + # Add linking to PackageCompiler.jl's libtrixi.so + target_link_libraries( ${PROJECT_NAME} INTERFACE ${PC_LIBTRIXI_SO} ) + # Install configuration install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/lib/" TYPE LIB ) install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/share/julia" From 533664437aae2146ee4f1c187b401018c81c37e6 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 14:39:42 +0200 Subject: [PATCH 11/20] adapt github workflow to use cmake for PackageCompiler.jl --- .github/workflows/ci.yml | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bb35832..fa30618c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -170,17 +170,21 @@ jobs: --julia-depot ~/.julia \ --force - - name: Build libtrixi using PackageCompiler + - name: Configure (test_type == 'package-compiler') if: ${{ matrix.test_type == 'package-compiler' }} run: | - cd LibTrixi.jl/lib - make + mkdir build + cd build + cmake .. -DCMAKE_INSTALL_PREFIX=../install \ + -DCMAKE_BUILD_TYPE=Debug \ + -DUSE_PACKAGE_COMPILER=ON \ + -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia - - name: Build example + - name: Build if: ${{ matrix.test_type == 'package-compiler' }} run: | - cd examples - make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build + cd build + make -j2 - name: Prepare coverage reporting if: ${{ matrix.test_type == 'coverage' }} From abb3b6118ae62776d79ebf07d4098a576824bbec Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 15:40:44 +0200 Subject: [PATCH 12/20] fix typo --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c2cd831d..e00cf769 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ if( USE_PACKAGE_COMPILER ) # Custom target for PackageCompiler.jl's libtrixi.so add_custom_target( PC_LIBTRIXI DEPENDS ${PC_LIBTRIXI_SO} ) - # Depency of main library target on PackageCompiler.jl target + # Dependency of main library target on PackageCompiler.jl target add_dependencies( ${PROJECT_NAME} PC_LIBTRIXI ) # Add linking to PackageCompiler.jl's libtrixi.so From 4ccc0a074449c3ad5d6038be2d0c050a8e09c774 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 16:27:32 +0200 Subject: [PATCH 13/20] use absolute path as cmake will change working directory --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa30618c..eaa2426f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -178,7 +178,7 @@ jobs: cmake .. -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_BUILD_TYPE=Debug \ -DUSE_PACKAGE_COMPILER=ON \ - -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia + -DLIBTRIXI_JULIA_PROJECT=$PWD/../libtrixi-julia - name: Build if: ${{ matrix.test_type == 'package-compiler' }} From eac99156dec8363a39a5d82f2c805d3bde2fb2e4 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Thu, 5 Oct 2023 18:27:24 +0200 Subject: [PATCH 14/20] fix path for running examples --- .github/workflows/ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eaa2426f..e9d8fe4c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -220,10 +220,10 @@ jobs: - name: Run examples if: ${{ matrix.test_type == 'package-compiler' }} run: | - cd examples + cd build/examples mpirun -n 2 simple_trixi_controller_c \ - ../libtrixi-julia \ - ../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl + ../../libtrixi-julia \ + ../../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl env: LIBTRIXI_DEBUG: all From 34bd76445e49ec675ed0db9a9a71d24d22097892 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Tue, 17 Oct 2023 15:15:30 +0200 Subject: [PATCH 15/20] Change back `LIBTRIXI_JULIA_PROJECT` --> `JULIA_PROJECT_PATH` :grimacing: --- .github/workflows/ci.yml | 6 +++--- CMakeLists.txt | 12 ++++++------ docs/src/developers.md | 2 +- test/c/CMakeLists.txt | 2 +- test/c/auxiliary.cpp | 2 +- test/c/interface_c.cpp | 2 +- test/c/simulation.cpp | 2 +- test/c/t8code.cpp | 2 +- test/fortran/CMakeLists.txt | 2 +- test/fortran/juliaCode_suite.f90 | 2 +- test/fortran/simulationRun_suite.f90 | 2 +- test/fortran/versionInfo_suite.f90 | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 889854f1..69e4ac9e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -99,7 +99,7 @@ jobs: cmake .. -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_BUILD_TYPE=Release \ -DT8CODE_PREFIX=$PWD/../t8code-local/prefix \ - -DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia + -DENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia - name: Configure (test_type == 'coverage') if: ${{ matrix.test_type == 'coverage' }} @@ -113,7 +113,7 @@ jobs: -DCMAKE_Fortran_FLAGS="-cpp --coverage -O0" \ -DCMAKE_EXE_LINKER_FLAGS="--coverage" \ -DCMAKE_SHARED_LINKER_FLAGS="--coverage" \ - -DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT=../libtrixi-julia + -DENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia - name: Build if: ${{ matrix.test_type == 'regular' || matrix.test_type == 'coverage' }} @@ -178,7 +178,7 @@ jobs: cmake .. -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_BUILD_TYPE=Debug \ -DUSE_PACKAGE_COMPILER=ON \ - -DLIBTRIXI_JULIA_PROJECT=$PWD/../libtrixi-julia + -DJULIA_PROJECT_PATH=$PWD/../libtrixi-julia - name: Build if: ${{ matrix.test_type == 'package-compiler' }} diff --git a/CMakeLists.txt b/CMakeLists.txt index e00cf769..3415f8cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,10 +47,10 @@ find_package( MPI REQUIRED ) # Find Google Test and test-drive on demand option( ENABLE_TESTING "Build tests using Google Test (C) and test-drive (Fortran)" ) if( ENABLE_TESTING ) - if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) - message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT not set, tests will not work.") + if ( NOT DEFINED JULIA_PROJECT_PATH ) + message( FATAL_ERROR "JULIA_PROJECT_PATH not set, tests will not work.") endif() - set( LIBTRIXI_JULIA_PROJECT ${LIBTRIXI_JULIA_PROJECT} CACHE PATH + set( JULIA_PROJECT_PATH ${JULIA_PROJECT_PATH} CACHE PATH "Path to Julia project (typically 'libtrixi-julia').") find_package( GTest REQUIRED ) @@ -67,8 +67,8 @@ option( USE_PACKAGE_COMPILER "Build standalone libtrixi.so using PackageCompiler set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) if( USE_PACKAGE_COMPILER ) - if ( NOT DEFINED LIBTRIXI_JULIA_PROJECT ) - message( FATAL_ERROR "LIBTRIXI_JULIA_PROJECT needs to be set for PackageCompiler.jl.") + if ( NOT DEFINED JULIA_PROJECT_PATH ) + message( FATAL_ERROR "JULIA_PROJECT_PATH needs to be set for PackageCompiler.jl.") endif() if ( ENABLE_TESTING ) message( NOTICE "Testing is not supported when PackageCompiler is used.") @@ -94,7 +94,7 @@ if( USE_PACKAGE_COMPILER ) COMMAND ${JULIA_EXECUTABLE} --project=${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/build.jl - ${LIBTRIXI_JULIA_PROJECT} + ${JULIA_PROJECT_PATH} ${CMAKE_BINARY_DIR}/prefix-pc WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) diff --git a/docs/src/developers.md b/docs/src/developers.md index d148ed1f..0ead48c8 100644 --- a/docs/src/developers.md +++ b/docs/src/developers.md @@ -50,7 +50,7 @@ For testing the C interface of libtrixi we rely on [GoogleTest](https://google.g The tests are contained in `cpp`-files located under `test/c`. They are processed by `cmake` and made available via `ctest`, provided the options ``` --DENABLE_TESTING=ON -DLIBTRIXI_JULIA_PROJECT= +-DENABLE_TESTING=ON -DJULIA_PROJECT_PATH= ``` are passed to `cmake` during configuration. The executables can then be found under `/test/c` (they will not be installed). To run them, execute diff --git a/test/c/CMakeLists.txt b/test/c/CMakeLists.txt index ab4f3d89..4ecc3202 100644 --- a/test/c/CMakeLists.txt +++ b/test/c/CMakeLists.txt @@ -40,7 +40,7 @@ foreach ( TEST ${TESTS} ) # pass julia project path target_compile_definitions( ${TARGET_NAME} PRIVATE - LIBTRIXI_JULIA_PROJECT=\"${LIBTRIXI_JULIA_PROJECT}\" ) + JULIA_PROJECT_PATH=\"${JULIA_PROJECT_PATH}\" ) # discover tests gtest_discover_tests( ${TARGET_NAME} ) diff --git a/test/c/auxiliary.cpp b/test/c/auxiliary.cpp index a69e956c..fa1dd101 100644 --- a/test/c/auxiliary.cpp +++ b/test/c/auxiliary.cpp @@ -6,7 +6,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; +const char * julia_project_path = JULIA_PROJECT_PATH; const char* default_depot_path = "julia-depot"; diff --git a/test/c/interface_c.cpp b/test/c/interface_c.cpp index 0d5b446c..a625e6c5 100644 --- a/test/c/interface_c.cpp +++ b/test/c/interface_c.cpp @@ -7,7 +7,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; +const char * julia_project_path = JULIA_PROJECT_PATH; // Example libexlixir const char * libelixir_path = diff --git a/test/c/simulation.cpp b/test/c/simulation.cpp index aa7de3af..0db32dc5 100644 --- a/test/c/simulation.cpp +++ b/test/c/simulation.cpp @@ -6,7 +6,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; +const char * julia_project_path = JULIA_PROJECT_PATH; // Example libexlixir const char * libelixir_path = diff --git a/test/c/t8code.cpp b/test/c/t8code.cpp index d15db3e3..b6bc8afe 100644 --- a/test/c/t8code.cpp +++ b/test/c/t8code.cpp @@ -5,7 +5,7 @@ extern "C" { } // Julia project path defined via cmake -const char * julia_project_path = LIBTRIXI_JULIA_PROJECT; +const char * julia_project_path = JULIA_PROJECT_PATH; // Example libexlixir const char * libelixir_path = diff --git a/test/fortran/CMakeLists.txt b/test/fortran/CMakeLists.txt index c4ac55c5..115cbee9 100644 --- a/test/fortran/CMakeLists.txt +++ b/test/fortran/CMakeLists.txt @@ -32,7 +32,7 @@ target_compile_options( ${TARGET_NAME} PRIVATE -cpp -Wall -Wextra -Werror -Wno-u # pass julia project path target_compile_definitions( ${TARGET_NAME} PRIVATE - LIBTRIXI_JULIA_PROJECT=\"${LIBTRIXI_JULIA_PROJECT}\" ) + JULIA_PROJECT_PATH=\"${JULIA_PROJECT_PATH}\" ) # add tests foreach ( TEST ${TESTS} ) diff --git a/test/fortran/juliaCode_suite.f90 b/test/fortran/juliaCode_suite.f90 index 507755b4..7e28492a 100644 --- a/test/fortran/juliaCode_suite.f90 +++ b/test/fortran/juliaCode_suite.f90 @@ -6,7 +6,7 @@ module juliaCode_suite public :: collect_juliaCode_suite - character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT + character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH contains diff --git a/test/fortran/simulationRun_suite.f90 b/test/fortran/simulationRun_suite.f90 index 0907f463..1f81eb6f 100644 --- a/test/fortran/simulationRun_suite.f90 +++ b/test/fortran/simulationRun_suite.f90 @@ -6,7 +6,7 @@ module simulationRun_suite public :: collect_simulationRun_suite - character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT + character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH character(len=*), parameter, public :: libelixir_path = & "../../../LibTrixi.jl/examples/libelixir_p4est2d_dgsem_euler_sedov.jl" diff --git a/test/fortran/versionInfo_suite.f90 b/test/fortran/versionInfo_suite.f90 index c20ef477..eb1cc88d 100644 --- a/test/fortran/versionInfo_suite.f90 +++ b/test/fortran/versionInfo_suite.f90 @@ -7,7 +7,7 @@ module versionInfo_suite public :: collect_versionInfo_suite - character(len=*), parameter, public :: julia_project_path = LIBTRIXI_JULIA_PROJECT + character(len=*), parameter, public :: julia_project_path = JULIA_PROJECT_PATH contains From 5d59dddaeeb526bbb6f322e91f1c957ce40f6487 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 18 Oct 2023 17:48:10 +0200 Subject: [PATCH 16/20] document usage of PackageCompiler --- README.md | 44 +++++++++++++++++++++++++++----------------- docs/src/index.md | 40 +++++++++++++++++++++++++--------------- 2 files changed, 52 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 8ff35e9f..3dffc16a 100644 --- a/README.md +++ b/README.md @@ -276,23 +276,33 @@ library with a C interface. This is possible with the use of the Julia package [PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl). To try this out, perform the following steps: -1. Initialize the project directory `libtrixi-julia` using `libtrixi-init-julia` as - described above. -2. Go to the `LibTrixi.jl/lib` directory in the repository root, - make sure that `PROJECT_DIR` (defined in `Makefile`) points to your `libtrixi-julia` directory, - and call `make`: - ```shell - cd LibTrixi.jl/lib - make - ``` -3. Go to the `examples` folder in the repository root and compile - `simple_trixi_controller_c`: - ```shell - cd examples - make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build - ``` - This will create a `simple_trixi_controller_c` file. -4. From inside the `examples` folder you should be able to run the example (in parallel) +1. Initialize the project directory `libtrixi-julia` using `libtrixi-init-julia` as + described above. +2. Build + + *using make* + - Go to the `LibTrixi.jl/lib` directory in the repository root, + make sure that `PROJECT_DIR` (defined in `Makefile`) points to your `libtrixi-julia` directory, + and call `make`: + ```shell + cd LibTrixi.jl/lib + make + ``` + - Go to the `examples` folder in the repository root and compile + `simple_trixi_controller_c`: + ```shell + cd examples + make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build + ``` + This will create a `simple_trixi_controller_c` file. + + *using cmake* + - Add + ``` + -DUSE_PACKAGE_COMPILER=ON -DJULIA_PROJECT_PATH= + ``` + to your cmake call (see above) +3. From inside the `examples` folder you should be able to run the example (in parallel) with the following command: ```shell mpirun -n 2 simple_trixi_controller_c \ diff --git a/docs/src/index.md b/docs/src/index.md index 45fea9a9..a7fa1564 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -278,21 +278,31 @@ library with a C interface. This is possible with the use of the Julia package To try this out, perform the following steps: 1. Initialize the project directory `libtrixi-julia` using `libtrixi-init-julia` as described above. -2. Go to the `LibTrixi.jl/lib` directory in the repository root, - make sure that `PROJECT_DIR` (defined in `Makefile`) point to your `libtrixi-julia` directory, - and call `make`: - ```shell - cd LibTrixi.jl/lib - make - ``` -3. Go to the `examples` folder in the repository root and compile - `simple_trixi_controller_c`: - ```shell - cd examples - make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build - ``` - This will create a `simple_trixi_controller_c` file. -4. From inside the `examples` folder you should be able to run the example (in parallel) +2. Build + + *using make* + - Go to the `LibTrixi.jl/lib` directory in the repository root, + make sure that `PROJECT_DIR` (defined in `Makefile`) points to your `libtrixi-julia` directory, + and call `make`: + ```shell + cd LibTrixi.jl/lib + make + ``` + - Go to the `examples` folder in the repository root and compile + `simple_trixi_controller_c`: + ```shell + cd examples + make -f MakefileCompiled LIBTRIXI_PREFIX=$PWD/../LibTrixi.jl/lib/build + ``` + This will create a `simple_trixi_controller_c` file. + + *using cmake* + - Add + ``` + -DUSE_PACKAGE_COMPILER=ON -DJULIA_PROJECT_PATH= + ``` + to your cmake call (see above) +3. From inside the `examples` folder you should be able to run the example (in parallel) with the following command: ```shell mpirun -n 2 simple_trixi_controller_c \ From 69c022debcc13f2de31cc0c12d3b8ed47af58935 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 18 Oct 2023 17:55:13 +0200 Subject: [PATCH 17/20] use file( COPY ...) --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3415f8cb..9d73f777 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -76,9 +76,8 @@ if( USE_PACKAGE_COMPILER ) # Copy source with initialization routines; an object file will be created file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) - file( COPY_FILE ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c - ${CMAKE_BINARY_DIR}/build-pc/init.c - ONLY_IF_DIFFERENT ) + file( COPY ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c + DESTINATION build-pc/ ) # Define PackageCompiler.jl output file set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) From b88c8550c9adb303c20dfd9e0bb7e2dcdb053504 Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Wed, 18 Oct 2023 18:00:16 +0200 Subject: [PATCH 18/20] consistent naming --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ad4a4dc2..107bbbe6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -183,7 +183,7 @@ jobs: -DUSE_PACKAGE_COMPILER=ON \ -DJULIA_PROJECT_PATH=$PWD/../libtrixi-julia - - name: Build + - name: Build (test_type == 'package-compiler') if: ${{ matrix.test_type == 'package-compiler' }} run: | cd build From f4942bf6f31cd992d31fe4b9f0820831b9faf9f7 Mon Sep 17 00:00:00 2001 From: Michael Schlottke-Lakemper Date: Thu, 19 Oct 2023 09:24:36 +0200 Subject: [PATCH 19/20] Update CMakeLists.txt --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d73f777..bad29249 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,8 +109,7 @@ if( USE_PACKAGE_COMPILER ) # Install configuration install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/lib/" TYPE LIB ) install( DIRECTORY "${CMAKE_BINARY_DIR}/prefix-pc/share/julia" - DESTINATION share - PATTERN "cert.pem" EXCLUDE ) + DESTINATION share ) else() # Library target add_library ( ${PROJECT_NAME} SHARED From 75344f58cb3e5ca694b0bc636a1f2f650dd6f00c Mon Sep 17 00:00:00 2001 From: Benedict Geihe Date: Fri, 20 Oct 2023 12:29:52 +0200 Subject: [PATCH 20/20] copy file using add_custom_command this allows to define dependencies --- CMakeLists.txt | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bad29249..c4d13125 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,14 +74,19 @@ if( USE_PACKAGE_COMPILER ) message( NOTICE "Testing is not supported when PackageCompiler is used.") endif() - # Copy source with initialization routines; an object file will be created - file( MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) - file( COPY ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c - DESTINATION build-pc/ ) - # Define PackageCompiler.jl output file set( PC_LIBTRIXI_SO ${CMAKE_BINARY_DIR}/prefix-pc/lib/libtrixi.so ) + # Define PackageCompiler.jl initialization source file + set( PC_INIT_SOURCE ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/init.c ) + set( PC_INIT_BUILD ${CMAKE_BINARY_DIR}/build-pc/init.c ) + + # Copy initialization source to build directory + add_custom_command( OUTPUT ${PC_INIT_BUILD} + COMMENT "Copying `init.c` to build folder..." + COMMAND ${CMAKE_COMMAND} -E copy ${PC_INIT_SOURCE} ${PC_INIT_BUILD} + DEPENDS ${PC_INIT_SOURCE} ) + # Add a library target (libtrixi), only for Fortran module add_library( ${PROJECT_NAME} OBJECT src/api.f90 @@ -95,6 +100,7 @@ if( USE_PACKAGE_COMPILER ) ${CMAKE_SOURCE_DIR}/LibTrixi.jl/lib/build.jl ${JULIA_PROJECT_PATH} ${CMAKE_BINARY_DIR}/prefix-pc + DEPENDS ${PC_INIT_BUILD} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/build-pc ) # Custom target for PackageCompiler.jl's libtrixi.so