Chapter 0#
The MUSICA CMake Package#
The MUSICA library installs with CMake musica
and musica_fortran
packages to facilitate linking
to higher level libraries and host models that have CMake build systems.
A minimal CMakeLists.txt
file designed to link the musica_fortran
library
to a Fortran program demo_f.f90
is exhibited below
cmake_minimum_required(VERSION 3.21) project( musica-demo VERSION 0.1 LANGUAGES CXX C Fortran ) # mkdir build # cd build # cmake -DMUSICA_INSTALL_DIR=<musica_install_dir> .. set(MUSICA_INCLUDE_DIR "${MUSICA_INSTALL_DIR}/include") set(MUSICA_LIB_DIR "${MUSICA_INSTALL_DIR}/lib") message(STATUS "${MUSICA_INCLUDE_DIR}") message(STATUS "${MUSICA_LIB_DIR}") add_executable(demo_f demo.f90) target_include_directories(demo_f PUBLIC ${MUSICA_INCLUDE_DIR}) target_link_directories(demo_f PUBLIC ${MUSICA_LIB_DIR}) target_link_libraries(demo_f musica-fortran musica stdc++)
These CMake directives are essentially equivalent to compilation on the command line via
gfortran -o demo_f demo_f.f90 -I<MUSICA_DIR>/include -L<MUSICA_DIR>/lib -lmusica-fortran -lmusica -lstdc++
<MUSICA_DIR>
is the full path of the MUSICA installation directory,
specified by the option CMAKE_INSTALL_PREFIX
during the cmake configuration process.
Common practice is to create a build
subdir (relative to the top level CMakeLists.txt
file, say).
mkdir build
cd build
The cmake
could then be invoked with:
cmake -DMUSICA_INSTALL_DIR <MUSICA_DIR> ..
cmake --build .