Code Monkey home page Code Monkey logo

pd.cmake's Introduction

pd.cmake

The repository offers a set of script to facilitate the creation of CMake projects to compile Pure Data externals. CMake is a free, open-source and cross-platform system that allows to generate makefiles and projects for many OS and build systems and/or IDEs (Unix makefile, XCode, Visual Studio, Code::Blocks, etc.). So the goal of the pd.cmake is to offer a system that allows to easily and quickly create projects for developing and compiling Pd externals on the environment of your choice.


  1. Pre-required
  2. Configuration
  3. Generation
  4. Github Actions
  5. Examples
  6. See Also

Pre-required

To compile Pd externals using pd.cmake, you need CMake (minimum version 3.18) and a build system or an IDE (like Unix MakeFile, XCode, Visual Studio, mingw64, etc.). You also need the Pure Data Sources, which are included within your Pure Data distribution and pd.cmake. If you use Git to manage your project, it is recommended to include pd.cmake as a submodule git submodule add https://github.com/pure-data/pd.cmake.

Configuration

The configuration of the CMakeLists with pd.cmake is pretty straight forward but depends on how you manage your project (folder, sources, dependencies, etc.). Here is an example that demonstrate the basic usage of the pd.cmake system:

# Define your standard CMake header (for example):
cmake_minimum_required(VERSION 3.18)

# Include pd.cmake (1):
set(PDCMAKE_DIR pd.cmake/ CACHE PATH "Path to pd.cmake")
include(${PDCMAKE_DIR}/pd.cmake)

# Declare the name of the project:
project(my_lib)

# Add one or several externals (5):
pd_add_external(obj_name1 Sources/obj1.c)

pd_add_external(obj_name2 Sources/obj2.cpp)

Further information:

  1. The path pd.cmake depends on where you installed pd.cmake, here we assume that _pd.cmake is localized at the root directory of you project.
  2. The compiled externals will be outputed in the build folder. When can choose the folder name using cmake . -B MY_OUTPUT_FOLDER.
  3. As of Pd 0.51-0 you can compile a "Double precision" Pd. If you intend to use your externals in such an environment, you must also compile them with double precision by adding this line -DPD_FLOATSIZE=64.
  4. The function adds a new subproject to the main project. This subproject matches to a new external allowing to compile only one object without compiling all the others. The first argument is the name of the object (used as TARGET name) and the third argument are the sources. If you use more than one file, you can use GLOB, in this case, we compile all .cpp files inside Sources.
file(GLOB EXTERNAL_SOURCES "${CMAKE_SOURCE_DIR}/Sources/*.cpp")
pd_add_external(myobj3 ${EXTERNAL_SOURCES})

Compilation

The generation of the build system or the IDE project is similar to any CMake project. The basic usage follows these steps from the project folder (where CMakeLists is localized):

cmake . -B build
cmake --build build

Tip

For big projects, you can use cmake --build build -j4 for a parallel build. Where 4 is the number of CPUs.

Variables

  • PDCMAKE_DIR: Define the PATH where is located pd.cmake.
  • PD_SOURCES_PATH: Define the PATH where is located m_pd.h.
  • PDLIBDIR: Define the PATH where the externals should be installed.
  • PDBINDIR: Define the PATH where is located pd.dll or pd64.dll (Just for Windows).
  • PD_FLOATSIZE: Define the float size (32 or 64).
  • PD_INSTALL_LIBS: Define if we must install the externals in PDLIBDIR or not (True or False).
  • PD_ENABLE_TILDE_TARGET_WARNING: Enable/Disable a warning when using target name (aka Object Name) with ~ (see details on Wiki).

Github Actions

pd.cmake offers an example for easily integrating GitHub Actions into your workflow (allowing automation for compiling the objects), it facilitates the compilation process for your PureData Library without the need for external resources or borrowing machines (for example). See more details on Wiki.

See Also

pd.cmake's People

Contributors

charlesneimog avatar pierreguillot avatar umlaeute avatar yoann-le-borgne avatar

Stargazers

Ben Wesch avatar

Watchers

Chris McCormick avatar  avatar Peter Brinkmann avatar  avatar Ben Wesch avatar Miller Puckette avatar  avatar

pd.cmake's Issues

out-of-tree builds

being able to build the same source into different flavours (defined by the build-system) is decidedly cool.

for this to work in all cases, the only directory we ever want to put stuff into is the build directory, never the source directory.
that is, the following should not return anything:

cmake -B _build
make -C _build
rm -rf _build
git status --porcelain --ignored

this means, that we must never put anything into CMAKE_(CURRENT_)SOURCE_DIR, only ever use CMAKE_(CURRENT_)BINARY_DIR to write files to.

i think c1acbcd tried to fix this, but got it wrong.

personally i would prefer if the default output path would just be the build directory, and not some subdir where i have to first search for the externals:

set(PD_OUTPUT_PATH ${CMAKE_CURRENT_BUILD_DIR} CACHE PATH "Path to the output of the external")

allow specifying the extension

there's some crude logic to calculate the external extension, but it is rather limited (only Linux, macOS and Windows; only amd64, arm64, and arm32) and its sometimes its plain wrong (for Pd64 externals).

i would suggest to add a new variable PD_EXTENSION that allows overriding the externsion (i's probably overkill to add code to correctly detect Pd64 on a PDP-11 running Minix, but it should be possible to build there as well)

TO-DO List

Variables

pd-lib-builder

  • PDDIR: Root directory of 'portable' pd package.

  • PDINCLUDEDIR: Directory where Pd API m_pd.h should be found, and other Pd header files. Overrides the default search path.

  • PDBINDIR: Directory where pd.dll should be found for linking (Windows only). Overrides the default search path.

  • PDLIBDIR: Root directory for installation of Pd library directories.

  • PDCMAKE_DIR: Used for the user of pd.cmake.

pd.cmake path/directory

as suggested by @umlaeute

set(PDCMAKE_DIR ${CMAKE_CURRENT_SOURCE_DIR} CACHE PATH "Path to pd.cmake")
include(${PDCMAKE_DIR}/pd.cmake)

Cross Compiling

@umlaeute for this, maybe we could create some special variables, because if I understood your email, this is not enough:

if ((CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") AND LINUX)

at least for me, cross compiling need to be easy for Github Actions. pd-else for example, not support arm Linux yet.

More TODOs

  • Not create files outside the build folder

README confused about 'PD_CMAKE_PATH' vs 'PDCMAKE_DIR'

reading the README, it is unclear whether one should use PD_CMAKE_PATH or PDCMAKE_DIR to set the location of pd.cmake.

we should strive for consistency with pd-lib-builder, but we must have internal consistency :-)
ideally we reach internal consistency while staying consistent with pd-lib-builder.

(also the confusion can be found in pd.cmake, Examples/CMakeLists.txt and Tests/01.Deprecated-Functions/CMakeLists.txt)

'PD_INSTALL_LIBS' acts way too early

if i add -DPD_INSTALL_LIBS=True, i expect that when I run make install (often as superuser) that the libraries are installed. (to be honest, i would expect a make install target to be present and do something similar, even if that flag was not set or False). Obviously for other generators it would be similar (but probably not the same).

Instead, what I get is, that cmake now tries to create directories during configuration stage, which i think is plain wrong.

steps to repdroduce:

mkdir _build
cd _build
cmake .. -DPD_INSTALL_LIBS=True

and it gives me a lot of errors:

-- The C compiler identification is GNU 13.2.0
-- The CXX compiler identification is GNU 13.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Pd Install Libs Path: /usr/local/lib/pd-externals
CMake Error at pd.cmake:141 (file):
  file failed to create directory:

    /usr/local/lib/pd-externals

  because: Permission denied
Call Stack (most recent call first):
  pd.cmake:280:EVAL:1 (pd_install_libs)
  Examples/CMakeLists.txt:DEFERRED


CMake Error at pd.cmake:141 (file):
  file failed to create directory:

    /usr/local/lib/pd-externals

  because: Permission denied
Call Stack (most recent call first):
  pd.cmake:280:EVAL:1 (pd_install_libs)
  Examples/CMakeLists.txt:DEFERRED


CMake Error at pd.cmake:141 (file):
  file failed to create directory:

    /usr/local/lib/pd-externals

  because: Permission denied
Call Stack (most recent call first):
  pd.cmake:280:EVAL:1 (pd_install_libs)
  Examples/CMakeLists.txt:DEFERRED


-- Configuring incomplete, errors occurred!

move build-system for examples into `Examples/`

we currently have a master CMakeLists.txt file in the project root, the sole purpose of which is to act as an example on how to use pd.cmake.

since it is just an example, i think it should be moved into the Examples/ subdirectory.

we could leave a Cmakefile in the root, that just calls the Examples.

this way, the examples are "self-contained" (without pd.cmake itself) and can also document how to include pd.cmake from arbitrary paths (see my PDCMAKE_DIR in #7 )

Default installation target

          ## About `PDLIBDIR`

@umlaeute I have some thoughts regarding the default PDLIBDIR path configuration:

Windows

Currently, pd-lib-builder uses %APPDATA%/Roaming/Pd as the default path. However, this is a hidden folder on Windows, making it somewhat inconvenient to access (personal opinion). I believe it would be more intuitive to use %HOME%/Documents/Pd/externals, which is the default path for PureData. What do you think?

Linux

For Linux, I suggest using /home/Documents/Pd/externals. In pd-lib-builder, the default path is /usr/local/lib/pd-externals, which requires sudo permissions to install. Using the home directory would simplify the installation process.

Mac

For macOS, I would also recommend placing it in the Documents folder. However, I need access to an Apple machine to verify this configuration.

Originally posted by @charlesneimog in #7 (comment)

drop binary blobs

i really think pd.lib (and pd.def) should be generated by Pd, and not included with this repo.

`add_pd_external`

I would simplify the add_pd_external function by reducing the number of arguments from three to two: one for the binary output name and one for the source code. Currently, the function takes three arguments: the library name, the binary output name, and the source code.

There's an issue with using the ~ character in the add_library function. We have two options to solve this:

Not allows the ~ char: FATAL_ERROR if the user set a output with the ~ character, something like: "You can't use the ~ character, replace it with _tilde."

Automatic Replacement: Automatically replace the ~ character, but this approach introduces more problems (as seen in the the test implementation in my repo's dev branch).

Current: add_pd_external(library_name, binary_output_name, source_code)
Suggested: add_pd_external(binary_output_name, source_code)

What do you think?

Originally posted by @charlesneimog in #7 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.