-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial cmake configuation and C skeletons (#1)
Co-authored-by: Michael Schlottke-Lakemper <[email protected]>
- Loading branch information
Showing
10 changed files
with
430 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
build | ||
|
||
# Ignore CMake files for bad users who do in-source builds | ||
CMakeCache.txt | ||
CMakeFiles/ | ||
Makefile | ||
cmake_install.cmake | ||
|
||
# Further ignore build products | ||
libtrixi.mod | ||
libtrixi.so* | ||
fortran_hello_world |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# Specify the minimum version. | ||
cmake_minimum_required ( VERSION 3.0 ) | ||
|
||
# Specify the project info. | ||
project ( trixi VERSION 0.1.0 DESCRIPTION "Interface library for using Trixi.jl from C/C++/Fortran" ) | ||
|
||
# Enable C and Fortran | ||
enable_language(C Fortran) | ||
|
||
# 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/" ) | ||
|
||
# Find Julia | ||
find_package( Julia REQUIRED ) | ||
|
||
include_directories( ${JULIA_INCLUDE_DIRS} ) | ||
|
||
|
||
|
||
# Find MPI | ||
find_package( MPI REQUIRED ) | ||
|
||
include_directories( ${MPI_C_INCLUDE_DIRS} ) | ||
|
||
|
||
|
||
# Library target | ||
add_library ( ${PROJECT_NAME} SHARED | ||
src/trixi.c | ||
src/trixi.h | ||
src/trixi.f90 | ||
) | ||
|
||
# Include directories, private | ||
target_include_directories ( ${PROJECT_NAME} PRIVATE src ) | ||
|
||
# Version info | ||
set_target_properties ( ${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} ) | ||
|
||
# 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 ) | ||
|
||
# Fortran mod file location | ||
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}) | ||
|
||
|
||
|
||
# Add examples | ||
add_subdirectory( examples ) | ||
|
||
|
||
|
||
# Install configuration | ||
install( TARGETS ${PROJECT_NAME} ) | ||
install( FILES ${CMAKE_Fortran_MODULE_DIRECTORY}/libtrixi.mod TYPE LIB) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,75 @@ | ||
# libtrixi | ||
|
||
Interface library for using Trixi.jl from C/C++/Fortran. | ||
|
||
**Note: This project is in a very early stage and anything (including the name and existence of this repository) can change without warning at any time.** | ||
**Note: This project is in a very early stage and subject to changes without warning at any time.** | ||
|
||
## Getting started | ||
|
||
### Prerequisites | ||
|
||
A local installation of `MPI` and `Julia` is required. | ||
|
||
### Get the sources | ||
|
||
```bash | ||
git clone [email protected]:trixi-framework/libtrixi.git | ||
``` | ||
|
||
### Building | ||
|
||
For building, `cmake` and its typical workflow is used. | ||
|
||
1. It is recommended to created an out-of-source build directory, e.g. | ||
|
||
```bash | ||
mkdir build | ||
cd build | ||
``` | ||
|
||
2. Call cmake | ||
|
||
```bash | ||
cmake -DCMAKE_INSTALL_PREFIX=<install_directory> .. | ||
``` | ||
|
||
`cmake` should find `MPI` and `Julia` automatically. If not, the directories | ||
can be specified manually. | ||
The `cmake` clients `ccmake` or `cmake-gui` could be useful. | ||
|
||
Specifying the directory `install_directory` for later installation is optional. | ||
|
||
3. Call make | ||
|
||
```bash | ||
make | ||
``` | ||
|
||
This will build and place `libtrixi.so` in the current directory along with its | ||
header and a Fortran `mod` file. Your application will have to include and link | ||
against these. | ||
|
||
Examples can be found in the `examples` subdirectory. | ||
|
||
4. Install (optional) | ||
|
||
```bash | ||
make install | ||
``` | ||
|
||
This will install all provided file to the specified location. | ||
|
||
### Testing | ||
|
||
Check out the `fortran_hello_world` example. | ||
|
||
## Authors | ||
Libtrixi was initiated by | ||
[Benedict Geihe](https://www.mi.uni-koeln.de/NumSim/) | ||
(University of Cologne, Germany) and | ||
[Michael Schlottke-Lakemper](https://lakemper.eu) | ||
(RWTH Aachen University/High-Performance Computing Center Stuttgart (HLRS), Germany), who | ||
are also its principal maintainers. | ||
|
||
## License | ||
Libtrixi is licensed under the MIT license (see [LICENSE.md](LICENSE.md)). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# | ||
# Stop if already found | ||
# | ||
if ( JULIA_FOUND ) | ||
return() | ||
endif() | ||
|
||
|
||
|
||
# | ||
# Find julia executable | ||
# | ||
find_program ( JULIA_EXECUTABLE julia DOC "Julia executable" ) | ||
|
||
if ( NOT JULIA_EXECUTABLE ) | ||
return() | ||
endif() | ||
|
||
|
||
|
||
# | ||
# Once julia is found, use julia-config | ||
# | ||
execute_process( | ||
COMMAND ${JULIA_EXECUTABLE} -e "print(dirname(Sys.BINDIR))" | ||
OUTPUT_VARIABLE JULIA_HOME | ||
RESULT_VARIABLE RESULT | ||
) | ||
if( NOT RESULT EQUAL 0 ) | ||
message( WARNING "Could not determine julia's bin directory" ) | ||
endif() | ||
|
||
execute_process( | ||
COMMAND ${JULIA_EXECUTABLE} -e "print(joinpath(Sys.BINDIR, Base.DATAROOTDIR, \"julia\"))" | ||
OUTPUT_VARIABLE JULIA_SHARE | ||
RESULT_VARIABLE RESULT | ||
) | ||
if( NOT RESULT EQUAL 0 ) | ||
message( WARNING "Could not determine julia's share directory" ) | ||
endif() | ||
|
||
|
||
|
||
# | ||
# Get flags | ||
# | ||
execute_process( | ||
COMMAND ${JULIA_SHARE}/julia-config.jl --cflags | ||
OUTPUT_VARIABLE JULIA_CFLAGS | ||
RESULT_VARIABLE RESULT | ||
) | ||
|
||
execute_process( | ||
COMMAND ${JULIA_SHARE}/julia-config.jl --ldflags | ||
OUTPUT_VARIABLE JULIA_LDFLAGS | ||
RESULT_VARIABLE RESULT | ||
) | ||
|
||
execute_process( | ||
COMMAND ${JULIA_SHARE}/julia-config.jl --ldlibs | ||
OUTPUT_VARIABLE JULIA_LDLIBS | ||
RESULT_VARIABLE RESULT | ||
) | ||
|
||
|
||
|
||
# | ||
# Julia includes | ||
# | ||
string ( REGEX REPLACE ".*-I'(.*)'.*" "\\1" JULIA_INCLUDE_DIRS ${JULIA_CFLAGS} ) | ||
set ( JULIA_INCLUDE_DIRS ${JULIA_INCLUDE_DIRS} CACHE PATH "Julia include directory" ) | ||
|
||
|
||
|
||
# | ||
# Julia library location | ||
# | ||
execute_process( | ||
COMMAND ${JULIA_EXECUTABLE} -e "using Libdl; print(abspath(dirname(Libdl.dlpath(\"libjulia\"))))" | ||
OUTPUT_VARIABLE JULIA_LIBRARY_DIR | ||
RESULT_VARIABLE RESULT | ||
) | ||
if( RESULT EQUAL 0 ) | ||
set( JULIA_LIBRARY_DIR ${JULIA_LIBRARY_DIR} CACHE PATH "Julia library directory" ) | ||
else() | ||
message( WARNING "Could not determine julia's library directory" ) | ||
endif() | ||
|
||
find_library( JULIA_LIBRARY | ||
NAMES julia | ||
PATHS ${JULIA_LIBRARY_DIR} | ||
) | ||
|
||
|
||
|
||
# | ||
# Extract julia version | ||
# | ||
execute_process( | ||
COMMAND ${JULIA_EXECUTABLE} --version | ||
OUTPUT_VARIABLE JULIA_VERSION_STRING | ||
RESULT_VARIABLE RESULT | ||
) | ||
|
||
if( RESULT EQUAL 0 ) | ||
string(REGEX REPLACE ".*([0-9]+\\.[0-9]+\\.[0-9]+).*" "\\1" JULIA_VERSION_STRING ${JULIA_VERSION_STRING} ) | ||
endif () | ||
|
||
|
||
|
||
# | ||
# Finalize | ||
# | ||
include ( FindPackageHandleStandardArgs ) | ||
find_package_handle_standard_args( | ||
Julia | ||
REQUIRED_VARS JULIA_LIBRARY JULIA_LIBRARY_DIR JULIA_INCLUDE_DIRS | ||
VERSION_VAR JULIA_VERSION_STRING | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Fortran Hello World | ||
# | ||
add_executable(fortran_hello_world fortran_hello_world.f90) | ||
|
||
target_link_directories(fortran_hello_world PRIVATE ${CMAKE_BINARY_DIR}) | ||
|
||
target_link_libraries(fortran_hello_world PRIVATE ${MPI_Fortran_LIBRARIES} ${PROJECT_NAME} ${JULIA_LIBRARY}) | ||
|
||
target_include_directories(fortran_hello_world PRIVATE ${MPI_Fortran_INCLUDE_DIRS}) | ||
|
||
# Set runtime path for installed binaries | ||
set_target_properties( fortran_hello_world PROPERTIES INSTALL_RPATH "../lib") | ||
|
||
install( TARGETS fortran_hello_world ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
program fortran_hello_world | ||
use LibTrixi | ||
|
||
implicit none | ||
|
||
include 'mpif.h' | ||
|
||
integer :: input(10) | ||
integer :: res | ||
integer i, ierror, rank, nranks, expected | ||
|
||
! Initialize MPI | ||
call MPI_Init(ierror) | ||
|
||
! Initialize Julia and Trixi | ||
call trixi_initialize(MPI_COMM_WORLD) | ||
|
||
! Say hello to julia | ||
call julia_eval_string('println("fortran: Hello julia!")') | ||
|
||
! Do a timestep | ||
call trixi_integrate() | ||
|
||
! Finalize Trixi and Julia | ||
call trixi_finalize() | ||
|
||
! Finalize MPI | ||
call MPI_Finalize(ierror) | ||
end program |
Oops, something went wrong.