1

I have an external project that generates a compiler

include(ExternalProject)

ExternalProject_Add(gprolog
        GIT_REPOSITORY    "[email protected]:didoudiaz/gprolog.git"
        GIT_TAG           "master"
        SOURCE_DIR        "${CMAKE_SOURCE_DIR}/3rdparty/gprolog"
        BUILD_IN_SOURCE   true
        CONFIGURE_COMMAND cd src && ./configure --with-install-dir=${CMAKE_SOURCE_DIR}/3rdparty/gprolog-build
        BUILD_COMMAND     cd src && make
        INSTALL_COMMAND   cd src && make install
)

Consequently, I'd like to run:

add_executable(runner src/runner.c app/application.pro)
include_directories(runner "${CMAKE_SOURCE_DIR}/3rdparty/gprolog-build/include")

but instead of gcc or clang, I need to use ${CMAKE_SOURCE_DIR}/3rdparty/gprolog-build/bin/gplc.

When I politely ask CMake to pretend that gplc is just another C compiler by adding

set(CMAKE_C_COMPILER "${CMAKE_SOURCE_DIR}/3rdparty/gprolog-build/bin/gplc")

it screams at me with

Cannot get compiler information:
    Compiler exited with error code 1: .../gprolog/3rdparty/gprolog-build/bin/gplc -xc -g -isysroot ..../Developer/SDKs/MacOSX11.3.sdk -fpch-preprocess -v -dD -E
    Apple clang version 12.0.5 (clang-1205.0.22.11)
    Target: x86_64-apple-darwin20.5.0
    Thread model: posix
    InstalledDir: .../XcodeDefault.xctoolchain/usr/bin
    clang: warning: -lm: 'linker' input unused [-Wunused-command-line-argument]
    clang: error: cannot specify -o when generating multiple output files
    compilation failed
1
  • Might be worth a feature request to support the gplc compiler. Commented Aug 18, 2021 at 1:19

1 Answer 1

1

Short of reverse engineering CMake's enable_language implementation modules to add your own for Prolog, you can always go the route of add_custom_command and ask your compiler to generate object files, which can be included as sources in the add_executable command.

If you add some detail to the question about how the Prolog compiler works, I can help you write the custom commands.

Sign up to request clarification or add additional context in comments.

2 Comments

I've pushed example code here: github.com/vasily-kartashov/gprolog-cmake
I got it to work on my Ubuntu machine by providing an appropriate toolchain file and overrides file. See my PR here: github.com/vasily-kartashov/gprolog-cmake/pull/1/files

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.