Skip to content

How do I add CBMC as a dependency in a cmake project using FetchContent? #7649

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jparsert opened this issue Apr 4, 2023 · 2 comments · Fixed by #7652
Closed

How do I add CBMC as a dependency in a cmake project using FetchContent? #7649

jparsert opened this issue Apr 4, 2023 · 2 comments · Fixed by #7652

Comments

@jparsert
Copy link

jparsert commented Apr 4, 2023

I am currently implementing something on top of a stub created by Elizabeth Polgreen based on Makefiles. As I am mostly used to Clion (and its IDE features) I was trying to use CMAKE to handle all dependencies etc. However, when using cmake's fetchContent I ran into a couple of issues.
The simplest one was the fact that when compiling the "-W-return-type" flag failed, which I fixed by adding
set (CMAKE_CXX_FLAGS "-Wno-return-type")

However, the issues I am not able to fix are the ones surrounding the scripts such as bash-autocomplete/extract_switches.sh.

So I was wondering if anyone else is using CMAKE/fetch_content and has anything to add. Also, here is the CMakeFile I am using to reproduce the errors:

cmake_minimum_required(VERSION 3.24)
project(CBMCTest)
include(FetchContent)

set(CMAKE_CXX_STANDARD 20)

set (CMAKE_CXX_FLAGS "-Wno-return-type")

FetchContent_Declare(cbmc
        GIT_REPOSITORY https://github.com/diffblue/cbmc
        GIT_TAG develop
        )
FetchContent_MakeAvailable(cbmc)

add_executable(CBMCTest main.cpp)

#probably some target_link_library(CBMCTest cprover goto .... etc.)

CBMC version: devel
Operating system: Linux kernel 6.2.8-1-MANJARO / Manjaro

@thomasspriggs
Copy link
Contributor

Hi. Both myself and @esteffin use CLion together with CMAKE for our work maintaining cbmc. Unfortunately neither of us currently use cbmc as a dependency using FetchContent, so we can't shed any light on making it work well without spending some time working out the issues in depth. I would suggest trying using add_subdirectory(lib/cbmc) to add the root of the cbmc repository to your project; substituting the correct path if necessary.

@jparsert
Copy link
Author

jparsert commented Apr 5, 2023

Thanks for the suggestion, I changed my project to use add_subdirectory now but I seem to be getting the same issues. Note that the CMakeLists.txt with the add_subdirectory is located in proj_root and cbmc is in proj_root/lib/cbmc. Then I get the following error

cd proj_root/cmake-build-debug/lib/cbmc/src/cbmc && proj_root/scripts/bash-autocomplete/extract_switches.sh

/bin/sh: line 1: proj_root/scripts/bash-autocomplete/extract_switches.sh: No such file or directory

It seems to be the same issue where these bash scripts are generated but not where they are supposed to.

My suspicion is that there is an absolute path to these bash files somewhere rather than a relative path. Hence, when they are called from a cmakefile outside of cbmc's root, the scripts are not located in the right place.

Edit:
After some investigation it seems to be an issues in those lines:

if(NOT WIN32)

I am no expert in Cmake but judging from this site: https://cmake.org/cmake/help/latest/variable/CMAKE_SOURCE_DIR.html
I suspect CMAKE_SOURCE_DIR should be changed to CMAKE_CURRENT_SOURCE_DIR. I will try and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants