adtzlr / ttb

Tensor Toolbox for Modern Fortran
https://adtzlr.github.io/ttb
MIT License
97 stars 31 forks source link

Cmake/Makefile for ttb #29

Open AliE89 opened 1 year ago

AliE89 commented 1 year ago

Hi @adtzlr, Thanks for this, it is going to be very useful!

In order to make your library easier to interface with existing codes, would you consider to do a CMakeLists.txt or a Makefile?

adtzlr commented 1 year ago

Hi, unfortunately I have absolutely no experience on that. Could you point me to some links or give a small example please?

AliE89 commented 1 year ago

Ok, fair enough :)

I have attached a Cmake file doing a static library for TTB. I needed to remove "ttb/" in the various include statements in ttb_libary.f in order to make it work.

CMake project file for TTB

PROJECT

cmake_minimum_required (VERSION 2.6) project (TTB) enable_language (Fortran)

Additional variables

set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake-modules/")

Compilers flag

set (CMAKE_Fortran_FLAGS "-O3 -ffast-math")

module locations

set(CMAKE_Fortran_MODULE_DIRECTORY "${CMAKE_BINARY_DIR}/mod") set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")

Library name

set(TARGET ttb)

Collect files

file(GLOB src "ttb/ttb_library.f") set_source_files_properties(${src} PROPERTIES LANGUAGE Fortran)

Add the library

add_library(${TARGET} ${src})

AliE89 commented 1 year ago

PS:

if you want the lib to be shared, just do add_library(${TARGET} SHARED ${src}) instead.

Thank you for your contribution!