2

I am quite new to the whole CMake logic and syntax. For the code I am working on, I need to use the cap_set_proc function to work with a process capabilities flags (man link). So I decided to start with a really stupid piece of code that you see here:

#include<iostream> #include<string> #include<sys/capability.h> using namespace std; int main(){ cap_t test = cap_get_proc(); string whatsTest(cap_to_text(test,nullptr)); cout<<whatsTest<<endl; return 0; } 

(For the moment, I do not care if the code I wrote makes any sense...)
Now, if I simply use c++ (as shown below) everything compiles fine and the executable runs without any issue:

c++ test_main.cpp -o test_cap -lcap 

The problem is that the project I am working one is pretty huge and relies on CMake pretty heavily. So I wanted to compile the same code but using CMake... How do I write a CMakeLists.txt file that allows me to obtain the same result as the compiler instruction shown in the previous lines?

1 Answer 1

6

Something like the following should be all you need:

cmake_minimum_required(VERSION 3.17) project(TestCapProject) # Add your executable target. add_executable(test_cap test_main.cpp) # Link the libcap library to your executable. target_link_libraries(test_cap PRIVATE cap) 

If you're adding this to an existing CMake project, you may only need the last two or three lines, depending on your project hierarchy.

I suggest reading through the CMake guide to get your bearings on some basic CMake commands.

The documentation for the two primary commands you need is here:

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

1 Comment

It worked just fine. Thanks for the help and also for the theory tips.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.