Packs with foreign code - Makefile and CMakeLists.txt in same pack - questions

In working with the pack

which currently has a Makefile for building looking to add the ability to build for native Windows using a CMakeLists.txt.

The SWI-Prolog documentation page for Packs with foreign code notes

configure
This preparation step is executed if one of CMakeLists.txt (cmake), configure, configure.in (autoconf), configure.ac or Makefile.am (automake) are found. The program to manage them is in parenthesis.

build
Build the process. When configured using (cmake) this will use (cmake). Otherwise either Makefile or makefile is expected and Unix make is used to build the process.

What I am not sure about is if both a Makefile and CMakeLists.txt exist, will different OSes or SWI -Prolog arch pick the correct means to build the pack, e.g.

will building on

  • Windows use CMakeLists.txt
  • Ubuntu use Makefile
  • MacOS use Makefile

I am currently working on testing the updated pack in a forked repository on Windows using Windows Sandbox and can possibly test Ubuntu using WSL 2, but have no way to test on MacOS.

Additionally should CMakeLists.txt avoid a section like

if(NOT SWIPL_CMAKE_LOADED AND NOT WIN32)
    # Unix standalone - try to find swipl and load its cmake module
   ...
endif()

The whole process is controlled by library(build/tool), which loads plug-ins. This says

% The plugins.  Load them in the order of preference.
:- use_module(conan).
:- use_module(cmake).
:- use_module(make).

:- multifile
    prolog:build_file/2,                % ?File, ?Toolchain
    prolog:build_step/4,                % ?Step, ?Tool, ?SrcDir, ?BuildDir
    prolog:build_environment/2,         % ?Name, ?Value
    prolog_pack:environment/2.          % ?Name, ?Value (backward compatibility)

Typically packages should provide one, these days preferably Cmake as it provides better portability. I see that the current rocksdb itself provides both a Makefile and CMakeLists.txt, so Ideally we use CMake to build the package.

I don’t know. Ideally we should not need a condition. The CMake import files are distributed, also with the Windows version. Now sure they apply though as they are generated by cross compiling. The easiest is probably to start with the demo pack "environ" pack for SWI-Prolog and test/fix installing that on Windows.

1 Like