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

**URL:** <https://swi-prolog.discourse.group/t/packs-with-foreign-code-makefile-and-cmakelists-txt-in-same-pack-questions/9464>\
**Category:** Pack\
**Created:** [December 28, 2025, 11:40am UTC](https://swi-prolog.discourse.group/t/packs-with-foreign-code-makefile-and-cmakelists-txt-in-same-pack-questions/9464 "2025-12-28T11:40:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [December 28, 2025, 11:40am UTC](https://swi-prolog.discourse.group/t/packs-with-foreign-code-makefile-and-cmakelists-txt-in-same-pack-questions/9464/1 "2025-12-28T11:40:51Z")

</div>

In working with the pack

> **[GitHub - JanWielemaker/rocksdb: SWI-Prolog interface for RocksDB](https://github.com/JanWielemaker/rocksdb)**
>
> SWI-Prolog interface for RocksDB

which currently has a [Makefile](https://github.com/JanWielemaker/rocksdb/blob/2b232e7fd445a380e1731b5a5a38c6e6dfe5ad7d/Makefile) for building looking to add the ability to build for native Windows using a [CMakeLists.txt](https://github.com/EricGT/rocksdb/blob/feature/windows-vcpkg-support/CMakeLists.txt).

The SWI-Prolog documentation page for [Packs with foreign code](https://www.swi-prolog.org/pldoc/man?section=pack-foreign) 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](https://www.swi-prolog.org/pldoc/man?section=flags#flag: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](https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/) and can possibly test Ubuntu using [WSL 2](https://learn.microsoft.com/en-us/windows/wsl/install), but have no way to test on MacOS.

Additionally should CMakeLists.txt avoid a section like

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

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [December 28, 2025, 2:41pm UTC](https://swi-prolog.discourse.group/t/packs-with-foreign-code-makefile-and-cmakelists-txt-in-same-pack-questions/9464/2 "2025-12-28T14:41:23Z")

</div>

> [@EricGT](#):
>
> What I am not sure about is if both a Makefile and CMakeLists.txt exist, will different OSes or SWI -Prolog [arch](https://www.swi-prolog.org/pldoc/man?section=flags#flag:arch) pick the correct means to build the pack, e.g.

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

```prolog
% 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.

> [@EricGT](#):
>
> Additionally should CMakeLists.txt avoid a section like
> 
> ```prolog
> if(NOT SWIPL_CMAKE_LOADED AND NOT WIN32)
> # Unix standalone - try to find swipl and load its cmake module
> ...
> endif()
> 
> ```

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](https://www.swi-prolog.org/pack/list?p=environ) and test/fix installing that on Windows.
