0

Trying to put Skia in my CMake project. How do I tell CMake to link my executable against libskia.a and use the header files inside ext/skia so that I can include them like so?

#include <skia/subdirectory/headerfile.h>

My project structure is currently the following:

.
├── CMakeLists.txt
├── CMakeLists.txt.user
├── ext
│   ├── libskia.a
│   └── skia
│       └── <subdirectories>
│           └── <header files>.h
└── src
    └── main.cpp

and my CMakeLists.txt:

cmake_minimum_required(VERSION 3.5)

project(project LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}")

add_executable(project src/main.cpp)
pixforge
  • 13
  • 2
  • target_link_libraries() is the command to tell CMake to link to a library. target_include_directories() is the command to tell CMake to add an include folder. You can also create an IMPORTED target: [https://stackoverflow.com/questions/25907478/possible-to-add-an-imported-library-to-target-link-libraries-that-takes-care-of](https://stackoverflow.com/questions/25907478/possible-to-add-an-imported-library-to-target-link-libraries-that-takes-care-of) – drescherjm Aug 17 '21 at 13:52
  • @drescherjm Alright, but where do I put these commands? Do I create a new CMakeLists.txt file somewhere else and put them there or do I put them in the root CMakeLists.txt? – pixforge Aug 17 '21 at 14:06

1 Answers1

1

In your primary CMakeLists.txt file you would simply add the following:

target_link_libraries(project skia)

If CMake cannot find the library, you can either do:

target_link_libraries(project /full/path/to/libskia.a)

or:

link_directories(/path/to/libraries)
target_link_libraries(project skia)
Dorito Johnson
  • 217
  • 1
  • 11