question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I’m tying to move my project from CMake to Meson; I currently use a CMake function to automatically compile some ODB headers; what it basically does is giving some paths and options to the ODB compiler and saving in a variable passed as parameter the generated source files, as well as exporting variables such as required libraries and include directories. Here’s some ugly CMake code

list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/OdbCmake/cmake/Modules")
find_package(ODB REQUIRED COMPONENTS pgsql)
include(${ODB_USE_FILE})
set(PROJECT_SOURCES src/main.cpp)
set(ODB_HEADERS src/table.hpp)
odb_compile(PROJECT_SOURCES FILES ${ODB_HEADERS} DB pgsql STANDARD "c++17")

target_link_libraries(project_name ${ODB_LIBRARIES})
target_include_directories(project_name ${ODB_INCLUDE_DIRS} ${ODB_COMPILE_OUTPUT_DIR})
target_compile_definitions(project_name DATABASE_PGSQL)

Unfortunately the documentations only describes how to compile subprojects, and is silent about executing CMake functions directly from the main project. Is this even possible?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mensindacommented, Jan 12, 2021

No, we won’t add support for calling CMake code from meson (besides the CMake subprojects and dependencies). Passing stuff from meson to CMake and then letting meson figure out what to do with the CMake output would be to error-prone and most likely more hassle for the user to set up than just using mesons custom_target.

0reactions
eli-schwartzcommented, Jan 12, 2021

If the cmake function is doing something non-trivial that many people might want to use in their projects, then the recommended way to handle this in meson is to submit a PR containing, either:

for looking up how to link stuff without pkg-config, https://mesonbuild.com/Dependencies.html#dependencies-with-custom-lookup-functionality

for helpers to use e.g. a special compiler for generating sources, a module, usable via

mod = import('foo')
mod.somefunction()

Modules must be built into meson because meson wishes to avoid custom functions and macros since it makes build systems hard to reason about when everyone reinvents the same wheel in vendored cmake snippets. Core modules get reviewed, achieve (hopefully) a well-thought-out API surface, and benefit everyone automatically.

Read more comments on GitHub >

github_iconTop Results From Across the Web

function — CMake 3.25.1 Documentation
A function opens a new scope: see set(var PARENT_SCOPE) for details. See the cmake_policy() command documentation for the behavior of policies inside functions....
Read more >
Functions in CMake - GitHub Pages
Know how to make a macro or a function in CMake. Let's take a look at making a CMake macro or function. ......
Read more >
CMake Functions and Macros - Asit Dhal - Medium
CMake supports both functions and macros to provide a named abstraction for some repetitive works. A function or macro always define a new...
Read more >
Programming in CMake
You can define your own CMake function or macro easily. The only difference between a function and a macro is scope; macros don't...
Read more >
CMake Functions and Macros
CMake is no different. It enables users to define both functions and macros allowing for encapsulation of repetitive tasks. However, they might ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found