Skip to content

Commit

Permalink
Build system updates for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ideoforms committed Oct 27, 2024
1 parent 99cd5e6 commit cf69360
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 51 deletions.
75 changes: 45 additions & 30 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,28 +54,34 @@ cmake_print_variables(CMAKE_PREFIX_PATH)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_MACOSX_RPATH 1)

#-------------------------------------------------------------------------------
# Shared compiler flags.
#-------------------------------------------------------------------------------

if (NOT MSVC)
if (MSVC)
#-------------------------------------------------------------------------------
# Windows Visual C: Enable parallelisation
#-------------------------------------------------------------------------------
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP")
else()
#-------------------------------------------------------------------------------
# GCC/Clang: Enable strict compiler warnings
#-------------------------------------------------------------------------------
add_compile_options(
-pedantic
-fPIC
-Wall
)
endif()

#-------------------------------------------------------------------------------
# Hide superfluous compiler warnings on macOS
#-------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(
-Wno-gnu-zero-variadic-macro-arguments
-Wno-vla-extension
)
#-------------------------------------------------------------------------------
# Hide superfluous compiler warnings on macOS
#-------------------------------------------------------------------------------
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_compile_options(
-Wno-gnu-zero-variadic-macro-arguments
-Wno-vla-extension
)
endif()
endif()


include_directories(
/usr/local/include
/opt/homebrew/include
Expand All @@ -86,13 +92,25 @@ include_directories(

if (${CMAKE_BUILD_TYPE} STREQUAL "Debug")
message("Building in debug mode")
add_compile_options(-ggdb3 -O0 -DDEBUG)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O1)
else()
add_compile_options(-ggdb3 -O0 -DDEBUG)
endif()
elseif (${CMAKE_BUILD_TYPE} STREQUAL "Release")
message("Building in release mode")
add_compile_options(-O3 -funroll-loops)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O2)
else()
add_compile_options(-O3 -funroll-loops)
endif()
else()
message("Building in dev mode")
add_compile_options(-O0)
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_compile_options(-O1)
else()
add_compile_options(-O0)
endif()
endif()

#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -129,34 +147,31 @@ add_library(signalflow SHARED ${SRC})
#-------------------------------------------------------------------------------
add_compile_definitions(SIGNALFLOW_VERSION="${SIGNALFLOW_VERSION}")

set(SNDFILE_BUILD_DIR "" CACHE PATH "Path to build sndfile library (will use find_library if blank)")

if (SNDFILE_BUILD_DIR)
set(SNDFILE_INCLUDE_DIR "${SNDFILE_BUILD_DIR}/../include" CACHE PATH "Path to sndfile include directory (ignored if SNDFILE_BUILD_DIR is blank")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(SNDFILE_BINARY_DIR "${PROJECT_SOURCE_DIR}/../libsndfile-1.2.2-win64" CACHE PATH "For Windows, path to downloaded sndfile directory")
add_definitions(-DHAVE_SNDFILE)
target_link_libraries(signalflow "${SNDFILE_BUILD_DIR}/sndfile")
include_directories(signalflow "${SNDFILE_BUILD_DIR}/include/")
include_directories(signalflow "${SNDFILE_INCLUDE_DIR}/")
target_link_libraries(signalflow "${SNDFILE_BINARY_DIR}/lib/sndfile.lib")
include_directories(signalflow "${SNDFILE_BINARY_DIR}/include/")
else()
find_library(SNDFILE sndfile)
if (SNDFILE)
message("Found sndfile")
add_definitions(-DHAVE_SNDFILE)
target_link_libraries(signalflow ${SNDFILE})
else()
message(SEND_ERROR "Couldn't find libsndfile")
else()
message(FATAL_ERROR "Couldn't find libsndfile")
endif()
endif()

if (NOT CMAKE_SYSTEM_NAME STREQUAL "Darwin")
set(FFTW_BUILD_DIR "" CACHE PATH "Path to prebuilt FFTW library (will use find_library if blank)")
set(FFTW_BUILD_DIR "${PROJECT_SOURCE_DIR}/../fftw-3.3.5-dll64" CACHE PATH "Path to prebuilt FFTW library (will use find_library if blank)")
if (FFTW_BUILD_DIR)
include_directories("${FFTW_BUILD_DIR}")
add_definitions(-DFFT_FFTW)
target_link_libraries(signalflow
"${FFTW_BUILD_DIR}/libfftw3-3"
"${FFTW_BUILD_DIR}/libfftw3f-3"
"${FFTW_BUILD_DIR}/libfftw3l-3"
"${FFTW_BUILD_DIR}/libfftw3-3.lib"
"${FFTW_BUILD_DIR}/libfftw3f-3.lib"
"${FFTW_BUILD_DIR}/libfftw3l-3.lib"
)
else()
find_library(FFTW3F fftw3f)
Expand Down Expand Up @@ -201,4 +216,4 @@ endif()
# Install shared lib and all includes
#-------------------------------------------------------------------------------
install(TARGETS signalflow DESTINATION lib)
install(DIRECTORY source/include/signalflow DESTINATION include)
install(DIRECTORY source/include/signalflow DESTINATION include)
2 changes: 1 addition & 1 deletion examples/euclidean-rhythm-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self, input=0, delay_time=1/8, feedback=0.7, wet=0.3):
pingpong = PingPongDelayPatch(mix)
pingpong.play()

graph.wait()
graph.wait(20)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion examples/hello-world-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def main():
# Play the
#------------------------------------------------------------------------
graph.play(stereo)
graph.wait()
graph.wait(2)

if __name__ == "__main__":
main()
7 changes: 0 additions & 7 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ install_requires =
numpy
package_dir =
= auxiliary/libs
packages =
signalflow-stubs
signalflow_midi
signalflow_cli
signalflow_examples
signalflow_visualisation
signalflow_analysis
include_package_data = true

[options.extras_require]
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def build_extension(self, ext):
signalflow_package_data = ['*.pyd']

setup(
packages=signalflow_packages,
ext_modules=[CMakeExtension('signalflow')],
cmdclass=dict(build_ext=CMakeBuild),
)
1 change: 0 additions & 1 deletion source/include/signalflow/node/io/output/miniaudio.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#pragma once

#include <soundio/soundio.h>
#include <vector>

#include "abstract.h"
Expand Down
4 changes: 3 additions & 1 deletion source/src/core/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
//#include <unistd.h>

namespace signalflow
{
Expand Down Expand Up @@ -169,6 +169,7 @@ void AudioGraph::start()
std::string recording_filename = recordings_dir + "/signalflow-" + timestamp_str + ".wav";

// TODO: This is all very POSIX-specific and won't work on Windows
/*
struct stat st;
if (stat(SIGNALFLOW_USER_DIR.c_str(), &st) == -1)
{
Expand All @@ -186,6 +187,7 @@ void AudioGraph::start()
throw std::runtime_error("AudioGraph: Failed creating recordings directory for auto_record (" + recordings_dir + ")");
}
}
*/
this->start_recording(recording_filename, this->output->get_num_input_channels());
}
}
Expand Down
21 changes: 11 additions & 10 deletions source/src/python/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,27 @@ void init_python_graph(py::module &m)

.def("wait", [](AudioGraph &graph) {
/*--------------------------------------------------------------------------------
* Interruptible wait
* https://pybind11.readthedocs.io/en/stable/faq.html#how-can-i-properly-handle-ctrl-c-in-long-running-functions
*-------------------------------------------------------------------------------*/
* Interruptible wait
* https://pybind11.readthedocs.io/en/stable/faq.html#how-can-i-properly-handle-ctrl-c-in-long-running-functions
*-------------------------------------------------------------------------------*/
for (;;)
{
if (PyErr_CheckSignals() != 0)
throw py::error_already_set();
/*--------------------------------------------------------------------------------
* Release the GIL so that other threads can do processing.
*-------------------------------------------------------------------------------*/
* Release the GIL so that other threads can do processing.
*-------------------------------------------------------------------------------*/
py::gil_scoped_release release;

std::this_thread::sleep_for(std::chrono::milliseconds(5));

if (graph.has_raised_audio_thread_error())
break;
}
})
.def(
"wait", [](AudioGraph &graph, float timeout_seconds) {
timeval tv;
gettimeofday(&tv, NULL);
double t0 = tv.tv_sec + tv.tv_usec / 1000000.0;
double t0 = signalflow_timestamp();

for (;;)
{
Expand All @@ -148,8 +148,7 @@ void init_python_graph(py::module &m)

if (timeout_seconds)
{
gettimeofday(&tv, NULL);
double t1 = tv.tv_sec + tv.tv_usec / 1000000.0;
double t1 = signalflow_timestamp();
if (t1 - t0 > timeout_seconds)
{
break;
Expand All @@ -161,6 +160,8 @@ void init_python_graph(py::module &m)
*-------------------------------------------------------------------------------*/
py::gil_scoped_release release;

std::this_thread::sleep_for(std::chrono::milliseconds(5));

if (graph.has_raised_audio_thread_error())
break;
}
Expand Down

0 comments on commit cf69360

Please sign in to comment.