Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make PackageCompiler.jl compilation selectable in cmake #128

Merged
merged 22 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
122 changes: 70 additions & 52 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
sloede marked this conversation as resolved.
Show resolved Hide resolved
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}
benegee marked this conversation as resolved.
Show resolved Hide resolved
${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} )
sloede marked this conversation as resolved.
Show resolved Hide resolved

# 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 $<$<COMPILE_LANGUAGE:C>:-std=gnu11>)
# Require Fortran 2018 standard for Fortran files
target_compile_options( ${PROJECT_NAME} PRIVATE $<$<COMPILE_LANGUAGE:Fortran>:-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 $<$<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 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 $<TARGET_OBJECTS:${PROJECT_NAME}_tls> 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 $<TARGET_OBJECTS:${PROJECT_NAME}_tls> 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()
2 changes: 1 addition & 1 deletion LibTrixi.jl/lib/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()]
benegee marked this conversation as resolved.
Show resolved Hide resolved

# Extract version from `Project.toml`
project_toml = joinpath(package_or_project_dir, "Project.toml")
Expand Down