1

So, one of my uni courses uses a meson.build system for one of the libraries we have to use. The library is organized like this

Now, using CLion, I have trouble linking to that library. Earlier I have been trying cloning it, and setting target_include_directories to the src and includefolders.

For some reason that didn't do the trick, and I'm now trying to convert the meson.build file to a CMakeFiles which I can just add/compile.

The file looks like:

project('animationwindow', ['c', 'cpp'], version: '0.01', default_options: ['cpp_std=c++17', 'default_library=static', 'buildtype=debugoptimized'])

if host_machine.system() == 'windows'
    sdl2_dep = subproject('sdl2_windows').get_variable('sdl2_windows_dep')
    sdl2image_dep = subproject('sdl2_image_windows').get_variable('sdl2_image_windows_dep')
else
    sdl2_dep = dependency('sdl2')
    sdl2image_dep = dependency('sdl2_image')
endif


build_files = [
    'src/internal/FontCache.cpp', 
    'src/internal/KeyboardKeyConverter.cpp',
    'src/internal/nuklear_implementation.cpp',
    'src/widgets/Button.cpp',
    'src/widgets/TextInput.cpp',
    'src/widgets/DropdownList.cpp',
    'src/AnimationWindow.cpp', 
    'src/Color.cpp', 
    'src/Image.cpp', 
    'src/Widget.cpp']
incdir = include_directories('include')
animationwindow = static_library('animationwindow', build_files, include_directories: incdir, dependencies: [sdl2_dep, sdl2image_dep], install: true)
install_subdir('include', install_dir: '.')
install_subdir('src', install_dir: '.')

animationwindow_dep = declare_dependency(link_with: animationwindow, include_directories: incdir)

import('pkgconfig').generate(animationwindow)

# ex = executable('prog', 'src/test.cpp', include_directories: incdir, dependencies: [sdl2_dep, imgui_dep], link_with: animationwindow)

I have converted that to:

cmake_minimum_required(VERSION 3.16)
project(animationwindow)

set(CMAKE_CXX_STANDARD 17)

find_package(SDL2 REQUIRED)

add_executable(
        animationwindow
        src/internal/FontCache.cpp
        src/internal/KeyboardKeyConverter.cpp
        src/internal/nuklear_implementation.cpp
        src/widgets/TextInput.cpp
        src/widgets/Button.cpp
        src/widgets/DropdownList.cpp
        src/AnimationWindow.cpp
        src/Color.cpp
        src/Image.cpp
        src/Widget.cpp
)

include_directories(animationwindow include)

The question now is, how do I link this from the main file. Can I just somehow link the CMakeLists, or do I have to precomile the library and then somehow add it?

Gronnmann
  • 13
  • 4
  • In CMake linkage is performed using [target_link_libraries](https://cmake.org/cmake/help/latest/command/target_link_libraries.html), which is described in almost any CMake tutorial. What problems in using this command in your case? BTW, your `meson.build` defines a **static library**: `static_library('animationwindow', ...)`, but your `CMakeLists.txt` defines the executable `(add_executable animationwindow ...)`). You probably want to use `add_library(animationwindow STATIC ...)` instead. – Tsyvarev Jan 16 '23 at 17:39
  • @Tsyvarev thanks a lot! I have now tried doing so, and the headers seem to be imported correctly. On compilation though, I now get "/usr/bin/ld: cannot find -ltdt4102_dependencies/animationwindow". Any idea how I might resolve that? – Gronnmann Jan 16 '23 at 19:50
  • For link with the library created in the same CMake project use its **target name**, not a *path*. – Tsyvarev Jan 16 '23 at 19:58

0 Answers0