Including external C++ libraries when building UGens

I have succesfully made my first super simple proof-of-concept UGen and have now proceeded to turning some of my C++ code into UGens. For these more elaborate UGens, I am relying on a my own C++ library (https://github.com/Adampultz/pultzLib) that lives in my root folder and not in the SuperCollider source code.

I would like to point to the path of this library in my CMakeLists.txt, but not sure how.
I have tried:

set(EXTERNAL_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Users/adammac2023/Documents/GitHub/pultzLib)

and

include_directories(${EXTERNAL_LIBRARY_DIR})

but get the error

fatal error: 'Leaky_Integrator.h' file not found

I suspect there’s more to be added to CMakeLists.txt.

What am I missing?

My second question is, whether it is smarter to clone my library into the “external_libraries” folder in the first place? I did already try that, but it still doesn’t find the header filer.

Here’s my full CmakeLists.txt:

####################################################################################################
# CMakeLists file for pl_RunningMaxDyn
# Generated by Adam Pultz
# 2023-11-14
####################################################################################################

####################################################################################################
# basic project config
cmake_minimum_required(VERSION 3.12)
set(project_name "pl_RunningMaxDyn")
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 17)

if(CMAKE_COMPILER_IS_GNUCXX) 
add_compile_options(-Wall -Wextra -pedantic)

endif(CMAKE_COMPILER_IS_GNUCXX)

####################################################################################################
# load modules
include(SuperColliderServerPlugin RESULT_VARIABLE server_plugin_found)
if(NOT server_plugin_found)
    message(FATAL_ERROR "Could not find server plugin functions module")
endif()

include(SuperColliderCompilerConfig RESULT_VARIABLE compiler_config_found)
if(NOT compiler_config_found)
    message(FATAL_ERROR "Could not find compiler config module")
endif()

# Windows - puts redistributable DLLs in install directory
include(InstallRequiredSystemLibraries)

sc_check_sc_path("${SC_PATH}")
message(STATUS "Found SuperCollider: ${SC_PATH}")
set(SC_PATH "${SC_PATH}" CACHE PATH
    "Path to SuperCollider source. Relative paths are treated as relative to this script" FORCE)

include("${SC_PATH}/SCVersion.txt")
message(STATUS "Building plugins for SuperCollider version: ${SC_VERSION}")

# set project here to avoid SCVersion.txt clobbering our version info
project(${project_name})
sc_do_initial_compiler_config() # do after setting project so compiler ID is available

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT OR NOT CMAKE_INSTALL_PREFIX)
    message(WARNING "No install prefix provided, defaulting to $BUILD_DIR/install")
    set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Install prefix" FORCE)
endif()

set(EXTERNAL_LIBRARY_DIR ${CMAKE_CURRENT_SOURCE_DIR}/Users/adammac2023/Documents/GitHub/pultzLib)

message(STATUS "Install directory set to: ${CMAKE_INSTALL_PREFIX}")

####################################################################################################
# options
option(SUPERNOVA "Build plugins for supernova" ON)
option(SCSYNTH "Build plugins for scsynth" ON)
option(NATIVE "Optimize for native architecture" OFF)
option(STRICT "Use strict warning flags" OFF)
option(NOVA_SIMD "Build plugins with nova-simd support." ON)

####################################################################################################
# include libraries

include_directories(${EXTERNAL_LIBRARY_DIR})

if (NOVA_SIMD)
	add_definitions(-DNOVA_SIMD)
	include_directories(${SC_PATH}/external_libraries/nova-simd)
endif()

####################################################################################################
# Begin target pl_RunningMaxDyn

set(pl_RunningMaxDyn_cpp_files
    plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.hpp
    plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.cpp
)
set(pl_RunningMaxDyn_sc_files
    plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.sc
)
set(pl_RunningMaxDyn_schelp_files
    plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.schelp
)

sc_add_server_plugin(
    "pl_RunningMaxDyn/pl_RunningMaxDyn" # desination directory
    "pl_RunningMaxDyn" # target name
    "${pl_RunningMaxDyn_cpp_files}"
    "${pl_RunningMaxDyn_sc_files}"
    "${pl_RunningMaxDyn_schelp_files}"
)

# End target pl_RunningMaxDyn
####################################################################################################

####################################################################################################
# END PLUGIN TARGET DEFINITION
####################################################################################################

message(STATUS "Generating plugin targets done")

And here’s my terminal output:

(base) adammac2023@Adams-Laptop build % cmake --build . --config Release
[ 25%] Building CXX object CMakeFiles/pl_RunningMaxDyn_scsynth.dir/plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.cpp.o
In file included from /Users/adammac2023/SuperCollider/TestUGens/pl_runningmaxdyn/plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.cpp:5:
/Users/adammac2023/SuperCollider/TestUGens/pl_runningmaxdyn/plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.hpp:7:10: fatal error: 'Leaky_Integrator.h' file not found
#include "Leaky_Integrator.h"
         ^~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/pl_RunningMaxDyn_scsynth.dir/plugins/pl_RunningMaxDyn/pl_RunningMaxDyn.cpp.o] Error 1
make[1]: *** [CMakeFiles/pl_RunningMaxDyn_scsynth.dir/all] Error 2
make: *** [all] Error 2

Hi Adam,

It seems like you’re appending an absolute path to the CMAKE_CURRENT_SOURCE_DIR path. Could this be the problem?

To address the issue @jpburstrom pointed out, I’d make your core library a git submodule so you have a consistent relative path to work with.