Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ jobs:
cmake .. -DCMAKE_INSTALL_PREFIX=../install \
-DCMAKE_BUILD_TYPE=Release \
-DT8CODE_ROOT=$PWD/../t8code-local/prefix \
-DENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia
-DLIBTRIXI_ENABLE_WARNINGS=ON -DLIBTRIXI_ENABLE_WERROR=ON \
-DLIBTRIXI_ENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia

- name: Configure (test_type == 'coverage')
if: ${{ matrix.test_type == 'coverage' }}
Expand All @@ -134,7 +135,8 @@ 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
-DLIBTRIXI_ENABLE_WARNINGS=ON -DLIBTRIXI_ENABLE_WERROR=ON \
-DLIBTRIXI_ENABLE_TESTING=ON -DJULIA_PROJECT_PATH=../libtrixi-julia

- name: Build
if: ${{ matrix.test_type == 'regular' || matrix.test_type == 'coverage' }}
Expand Down
91 changes: 62 additions & 29 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Specify the minimum version
# 3.9 required for regex submatches
# 3.12 required for policy CMP0074 (using *_ROOT variables)
cmake_minimum_required ( VERSION 3.12 )
# 3.13 required for policy CMP0076 (target_sources() command converts relative paths to absolute)
cmake_minimum_required ( VERSION 3.13 )

# Reconfigure if Project.toml has changed
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/LibTrixi.jl/Project.toml")
Expand All @@ -23,13 +24,26 @@ file(WRITE "${CMAKE_BINARY_DIR}/LIBTRIXI_VERSION" "${LIBTRIXI_VERSION}\n")
project ( trixi VERSION ${LIBTRIXI_VERSION_MAJOR}.${LIBTRIXI_VERSION_MINOR}.${LIBTRIXI_VERSION_PATCH}
DESCRIPTION "Interface library for using Trixi.jl from C/C++/Fortran" )

# Enable C and Fortran
enable_language(C Fortran)
# Additional configuration options
option( LIBTRIXI_BUILD_FORTRAN_API "Enable the build of the Fortran interface" ON )
option( LIBTRIXI_ENABLE_WARNINGS "Use compilation flags -Wall -Wextra" OFF )
option( LIBTRIXI_ENABLE_WERROR "Use compilation flag -Werror" OFF )
option( LIBTRIXI_ENABLE_TESTING "Build tests using Google Test (C) and test-drive (Fortran)" OFF )

# Enabling setting rpath for installation
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Define the warnings to use if enabled
set (LIBTRIXI_WARNING_OPTIONS -Wall -Wextra)
set (LIBTRIXI_WERROR_OPTION -Werror)

# Enable C always
enable_language( C )

# Optionally enable Fortran
if( LIBTRIXI_BUILD_FORTRAN_API )
enable_language( Fortran )
endif()

# Enabling setting rpath for installation
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Additional cmake modules
list ( APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" )
Expand All @@ -47,8 +61,7 @@ endif()
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( LIBTRIXI_ENABLE_TESTING )
if ( NOT DEFINED JULIA_PROJECT_PATH )
message( FATAL_ERROR "JULIA_PROJECT_PATH not set, tests will not work.")
endif()
Expand All @@ -57,22 +70,26 @@ if( ENABLE_TESTING )

find_package( GTest REQUIRED )

set ( TEST_DRIVE_FIND_METHOD fetch )
# Option TEST_DRIVE_BUILD_TESTING is hard-coded to ON, could be spared
find_package( test-drive REQUIRED )
if( LIBTRIXI_BUILD_FORTRAN_API )
set ( TEST_DRIVE_FIND_METHOD fetch )
# Option TEST_DRIVE_BUILD_TESTING is hard-coded to ON, could be spared
find_package( test-drive REQUIRED )
endif()
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( LIBTRIXI_BUILD_FORTRAN_API )
# Fortran mod file location
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR})
endif()

if( USE_PACKAGE_COMPILER )
if ( NOT DEFINED JULIA_PROJECT_PATH )
message( FATAL_ERROR "JULIA_PROJECT_PATH needs to be set for PackageCompiler.jl.")
endif()
if ( ENABLE_TESTING )
if ( LIBTRIXI_ENABLE_TESTING )
message( NOTICE "Testing is not supported when PackageCompiler is used.")
endif()

Expand All @@ -89,10 +106,12 @@ if( USE_PACKAGE_COMPILER )
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
)
if( LIBTRIXI_BUILD_FORTRAN_API )
# Add a library target (libtrixi), only for Fortran module
add_library( ${PROJECT_NAME} OBJECT
src/api.f90
)
endif()

# Custom command to run PackageCompiler.jl to produce libtrixi.so
add_custom_command( OUTPUT ${PC_LIBTRIXI_SO}
Expand Down Expand Up @@ -123,12 +142,18 @@ else()
# Library target
add_library ( ${PROJECT_NAME} SHARED
src/api.c
src/api.f90
src/auxiliary.h
src/auxiliary.c
src/trixi.h
)

# Build Fortran library target on demand
if( LIBTRIXI_BUILD_FORTRAN_API )
target_sources (${PROJECT_NAME} PRIVATE
src/api.f90
)
Comment thread
benegee marked this conversation as resolved.
endif()

# Include directories, private
target_include_directories ( ${PROJECT_NAME} PRIVATE src )

Expand All @@ -138,8 +163,6 @@ else()
# Version info for the shared object
set_target_properties ( ${PROJECT_NAME} PROPERTIES SOVERSION ${PROJECT_VERSION_MAJOR} )



# Include directories
target_include_directories( ${PROJECT_NAME} PRIVATE src ${JULIA_INCLUDE_DIRS} )

Expand All @@ -148,42 +171,52 @@ else()

# Set appropriate compile flags
target_compile_options( ${PROJECT_NAME} PUBLIC "-fPIC" )
target_compile_options( ${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror)

# Potentially, enable warnings
if( LIBTRIXI_ENABLE_WARNINGS )
target_compile_options( ${PROJECT_NAME} PRIVATE ${LIBTRIXI_WARNING_OPTIONS})
endif()

# Potentially, enable to interpret warnings as errors
if( LIBTRIXI_ENABLE_WERROR )
target_compile_options( ${PROJECT_NAME} PRIVATE ${LIBTRIXI_WERROR_OPTION})
endif()

# Require C11 standard with GNU extensions for C files
target_compile_options( ${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:C>:-std=gnu11>)
# Require Fortran 2018 standard for Fortran files
target_compile_options( ${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:-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 test on demand
if( ENABLE_TESTING )
if( LIBTRIXI_ENABLE_TESTING )
enable_testing()
add_subdirectory( test/c )
add_subdirectory( test/fortran )
endif()

if( LIBTRIXI_BUILD_FORTRAN_API )
add_subdirectory( test/fortran )
endif()
endif()

# Install configuration
install( FILES $<TARGET_OBJECTS:${PROJECT_NAME}_tls> TYPE LIB RENAME lib${PROJECT_NAME}_tls.o )
install( FILES "${CMAKE_BINARY_DIR}/LIBTRIXI_VERSION" DESTINATION share/julia )
endif()



# 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 PATTERN "lib" EXCLUDE )
install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE)
if( LIBTRIXI_BUILD_FORTRAN_API )
install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE INCLUDE)
endif()
install( PROGRAMS utils/libtrixi-init-julia TYPE BIN )

# Add examples
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ For building, `cmake` and its typical workflow is used.
- Specifying the directory `install_directory` for later installation is optional.
- Optional specification of build type sets some default compiler options for optimized
or debug code.
- By default the Fortran-Interface is built; it may be excluded with `DLIBTRIXI_BUILD_FORTRAN_API=OFF`.
Comment thread
benegee marked this conversation as resolved.
- Optional compiler options `-Wall -Wextra` are specified with `-DLIBTRIXI_ENABLE_WARNINGS=ON`.
- Optional compiler option `-Werror` is specified with `-DLIBTRIXI_ENABLE_WERROR=ON`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, we have been very strict with respect to warning, because we could. I would thus like to keep it this way, or at least have them on by default.

Regarding the Julia 1.12 issue: #259 (comment)
Currently I would set -DCMAKE_C_FLAGS="-Wno-error=unused-parameter" when running cmake.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any strong opinions on this @sloede ?

- Building of the test is enabled with `-DLIBTRIXI_ENABLE_TESTING=ON`.
- Building with t8code support is optional. It requires to pass
`-DT8CODE_ROOT=<t8code_install_directory>`.

Expand Down
19 changes: 16 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ if ( NOT T8CODE_FOUND )
list( FILTER EXAMPLES EXCLUDE REGEX "trixi_controller_baroclinic.*" )
endif()

if (NOT LIBTRIXI_BUILD_FORTRAN_API)
# Remove Fortran files if the the Fortran API is not build
list( FILTER EXAMPLES EXCLUDE REGEX ".*\.f90" )
endif()

foreach ( EXAMPLE ${EXAMPLES} )

get_filename_component ( EXAMPLE_EXT ${EXAMPLE} EXT )
Expand Down Expand Up @@ -53,7 +58,9 @@ foreach ( EXAMPLE ${EXAMPLES} )
${TARGET_NAME}
PRIVATE ${CMAKE_SOURCE_DIR}/src
)
if ( T8CODE_FOUND )

if ( LIBTRIXI_BUILD_FORTRAN_API AND T8CODE_FOUND )
# Add the t8code include directory of the Fortran module file for the Fortran compiler to find the module files
target_include_directories( ${TARGET_NAME} PRIVATE ${T8CODE_ROOT}/include/t8_fortran_interface/ )
endif()

Expand All @@ -66,8 +73,14 @@ foreach ( EXAMPLE ${EXAMPLES} )
# position independent code
target_compile_options( ${TARGET_NAME} PRIVATE "-fPIC" )

# enable warnings
target_compile_options( ${TARGET_NAME} PRIVATE -Wall -Wextra -Werror )
# Potentially, enable all warnings
if( LIBTRIXI_ENABLE_ALL_WARNINGS )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WARNING_OPTIONS})
endif()
# Potentially, enable to interpret warnings as errors
if( LIBTRIXI_ENABLE_WERROR )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WERROR_OPTION})
endif()

# add to installation
install( TARGETS ${TARGET_NAME} )
Expand Down
11 changes: 9 additions & 2 deletions test/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,15 @@ foreach ( TEST ${TESTS} )
PRIVATE ${CMAKE_SOURCE_DIR}/src
)

# enable warnings
target_compile_options( ${TARGET_NAME} PRIVATE -Wall -Wextra -Werror )
# Potentially, enable warnings
if( LIBTRIXI_ENABLE_WARNINGS )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WARNING_OPTIONS})
endif()

# Potentially, enable to interpret warnings as errors
if( LIBTRIXI_ENABLE_WERROR )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WERROR_OPTION})
endif()

# pass julia project path
target_compile_definitions( ${TARGET_NAME} PRIVATE
Expand Down
12 changes: 11 additions & 1 deletion test/fortran/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,17 @@ if ( T8CODE_FOUND )
endif()

# enable warnings
target_compile_options( ${TARGET_NAME} PRIVATE -cpp -Wall -Wextra -Werror -Wno-uninitialized )
target_compile_options( ${TARGET_NAME} PRIVATE -cpp -Wno-uninitialized )

# Potentially, enable warnings
if( LIBTRIXI_ENABLE_WARNINGS )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WARNING_OPTIONS})
endif()

# Potentially, enable to interpret warnings as errors
if( LIBTRIXI_ENABLE_WERROR )
target_compile_options( ${TARGET_NAME} PRIVATE ${LIBTRIXI_WERROR_OPTION})
endif()

# pass julia project path
target_compile_definitions( ${TARGET_NAME} PRIVATE
Expand Down
Loading