Szymon Marczak
Szymon Marczak

Reputation: 1093

How to import library in CMake

I'm new with C++.

Here's my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)
project(HelloWorld)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")

set(SOURCE_FILES main.cpp)
add_executable(HelloWorld ${SOURCE_FILES})

I tried include_directories(${PROJECT_SOURCE_DIR}/websocketpp) (target_include_directories too), but it didn't work. The library is in project folder. Should I put it somewhere else?

I got this:

C:\Users\Marczak\ClionProjects\HelloWorld\main.cpp:2:23: fatal error: websocketpp: No such file or directory`.

websocketpp is header only library.

How to import it properly?

Upvotes: 0

Views: 2096

Answers (1)

milleniumbug
milleniumbug

Reputation: 15834

You use target_include_directories to point at the directory the header files are in (in this case, directory of the library), and you include the specific headers you need (See the examples), not the entire directory.

echo_client example includes #include <websocketpp/client.hpp>. You may want to start with that.

Upvotes: 2

Related Questions