Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

target_compile_definitions from import cmake project not working correctly #7299

Closed
BinaryCat17 opened this issue Jun 11, 2020 · 7 comments
Closed
Assignees
Labels
dependency:cmake Issues related to `dependency` with the `cmake` method subprojects/wraps
Milestone

Comments

@BinaryCat17
Copy link

I try to use this cmake library https://github.com/felixguendling/cista
In CmakeLists line: target_compile_definitions(cista INTERFACE CISTA_${CISTA_HASH}=1) passed to the compiler incorrectly.
On the cmake site https://cmake.org/cmake/help/latest/command/target_compile_definitions.html says that prefix -D not required, but meson doesn’t think so and pass to compiler two definitions at once: CISTA_FNV1A=1 -DCISTA_FNV1A=1 - ???
Change line to target_compile_definitions(cista INTERFACE -DCISTA_${CISTA_HASH}=1)
fix this problem.

But there is another library that does similar things and everything works fine:
target_compile_definitions(spdlog PUBLIC SPDLOG_COMPILED_LIB)
I think the problem is with INTERFACE or with parameter = 1

@fzwoch
Copy link
Contributor

fzwoch commented Jun 11, 2020

Same with:

https://github.com/juce-framework/JUCE/tree/juce6

E.g:

JUCE/extras/Build/CMake/JUCEUtils.cmake(513): target_compile_definitions(juce_analytics INTERFACE JUCE_MODULE_AVAILABLE_juce_analytics=1 )

Ends up as:

JUCE_MODULE_AVAILABLE_juce_analytics=1 LINUX=1 -DJUCE_MODULE_AVAILABLE_juce_analytics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_basics=1 -DLINUX=1

in the Linker command line which breaks compilation.

@mensinda mensinda added dependency:cmake Issues related to `dependency` with the `cmake` method subprojects/wraps labels Jun 11, 2020
@mensinda mensinda added this to the 0.54.3 milestone Jun 11, 2020
@mensinda mensinda self-assigned this Jun 11, 2020
@mensinda
Copy link
Member

Which meson and CMake version are you using? I am unable to reproduce this bug with meson 0.54.2 and CMake 3.17.3

It is generally recommended to use the latest meson and CMake version when using CMake subprojects. Can you also please both check if this issue is still present in the meson master and 0.54 branch?

@mensinda
Copy link
Member

Removing this from the 0.54.3 milestone, since the relevant tests in #7309 pass.

@mensinda mensinda removed this from the 0.54.3 milestone Jun 12, 2020
@BinaryCat17
Copy link
Author

cmake version 3.17.3
meson version 0.54.2
I tried again and this bug repeated

Here is a link to my repository with a problem: https://github.com/ComradeStalin17/RiEngine

And I found 1 more problem with cmake and c ++ 20: WARNING: Unknown cpp_std "c++20" -> Ignoring. Try setting the project-level cpp_std if build errors occur. It occurs during build magic_enum which optionally uses c ++ 20. Try build my project, all dependencies will be installed by themselves.

@fzwoch
Copy link
Contributor

fzwoch commented Jun 13, 2020

I was trying with

$ meson --version
0.54.2

$ $ /home/fzwoch/Downloads/cmake-3.18.0-rc1-Linux-x86_64/bin/cmake --version
cmake version 3.18.0-rc1

# JUCE
https://github.com/juce-framework/JUCE/tree/3a9e26b26cc5e6d06d454f4f876caea23cbe7ede

Building JUCE DemoRunner by itself with CMake succeeds (make DemoRunner)

Trying using meson with this simple dummy project (main.c being an empty main(){})

project('test', 'c', 'cpp')

cmake = import('cmake')

sub_proj = cmake.subproject('JUCE')

executable('juce_test', 'main.c',
    dependencies : [
        sub_proj.dependency('juce_analytics'),
    ],
)
$ CMAKE=/home/fzwoch/Downloads/cmake-3.18.0-rc1-Linux-x86_64/bin/cmake meson build
The Meson build system
Version: 0.54.2
Source dir: /home/fzwoch/code/x
Build dir: /home/fzwoch/code/x/build
Build type: native build
Project name: test
Project version: undefined
C compiler for the host machine: cc (gcc 9.3.0 "cc (Debian 9.3.0-13) 9.3.0")
C linker for the host machine: cc ld.bfd 2.34
C++ compiler for the host machine: c++ (gcc 9.3.0 "c++ (Debian 9.3.0-13) 9.3.0")
C++ linker for the host machine: c++ ld.bfd 2.34
Host machine cpu family: x86_64
Host machine cpu: x86_64

|Executing subproject JUCE method cmake 
|
|Using 'CMAKE' from environment with value: '/home/fzwoch/Downloads/cmake-3.18.0-rc1-Linux-x86_64/bin/cmake'
|Found CMake: /home/fzwoch/Downloads/cmake-3.18.0-rc1-Linux-x86_64/bin/cmake (3.18.0)
|
||Configuring the build directory with CMake version 3.18.0
||Running: -DCMAKE_C_COMPILER=cc -DCMAKE_CXX_COMPILER=c++ -G Ninja -DCMAKE_INSTALL_PREFIX=/usr/local
||  - build directory:          /home/fzwoch/code/x/build/subprojects/JUCE/__CMake_build
||  - source directory:         /home/fzwoch/code/x/subprojects/JUCE
||  - trace args:               --trace-expand --trace-format=json-v1 --no-warn-unused-cli --trace-redirect=cmake_trace.txt
||  - preload file:             /usr/local/lib/python3.8/dist-packages/mesonbuild/cmake/data/preload.cmake
||  - disabled policy warnings: [CMP0025, CMP0047, CMP0056, CMP0060, CMP0065, CMP0066, CMP0067, CMP0082, CMP0089]
||
||Running with expanded trace output on.
||Not searching for unused variables given on the command line.
||Trace will be written to cmake_trace.txt
||-- The C compiler identification is GNU 9.3.0
||-- The CXX compiler identification is GNU 9.3.0
||-- Detecting C compiler ABI info
||-- Detecting C compiler ABI info - done
||-- Check for working C compiler: /usr/bin/cc - skipped
||-- Detecting C compile features
||-- Detecting C compile features - done
||-- Detecting CXX compiler ABI info
||-- Detecting CXX compiler ABI info - done
||-- Check for working CXX compiler: /usr/bin/c++ - skipped
||-- Detecting CXX compile features
||-- Detecting CXX compile features - done
||-- Found PkgConfig: /usr/bin/pkg-config (found version "0.29.2") 
||-- Checking for module 'libcurl'
||--   Found libcurl, version 7.68.0
||-- Checking for modules 'webkit2gtk-4.0;gtk+-x11-3.0'
||--   Found webkit2gtk-4.0, version 2.28.2
||--   Found gtk+-x11-3.0, version 3.24.20
||-- Checking for module 'alsa'
||--   Found alsa, version 1.2.2
||-- Checking for module 'freetype2'
||--   Found freetype2, version 23.1.17
||-- Configuring juceaide
||-- Building juceaide
||-- Exporting juceaide
||-- Configuring done
||-- Generating done
||-- Build files have been written to: /home/fzwoch/code/x/build/subprojects/JUCE/__CMake_build
|
|CMake configuration: SUCCEEDED
|CMake project JUCE has 36 build targets.
|
||Processing generated meson AST
||Build file: /home/fzwoch/code/x/build/subprojects/JUCE/meson.build
||
||Project name: JUCE
||Project version: undefined
||Program /usr/local/lib/python3.8/dist-packages/mesonbuild/cmake/data/run_ctgt.py found: YES (/usr/local/lib/python3.8/dist-packages/mesonbuild/cmake/data/run_ctgt.py)
||Build targets in project: 0
||Subproject JUCE finished.
|

Build targets in project: 1

test undefined

  Subprojects
    JUCE: YES

Found ninja-1.10.0 at /usr/bin/ninja
fzwoch@osmi:~/code/x$ ninja -C build/
ninja: Entering directory `build/'
[1/2] Compiling C object 'juce_test@exe/main.c.o'
FAILED: juce_test@exe/main.c.o 
cc -Ijuce_test@exe -I. -I.. -I../subprojects/JUCE/modules -Isubprojects/JUCE/__CMake_build -I../subprojects/JUCE/__CMake_build -Isubprojects/JUCE -I../subprojects/JUCE -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g JUCE_MODULE_AVAILABLE_juce_analytics=1 LINUX=1 -DJUCE_MODULE_AVAILABLE_juce_analytics=1 -DJUCE_MODULE_AVAILABLE_juce_gui_basics=1 -DLINUX=1 -MD -MQ 'juce_test@exe/main.c.o' -MF 'juce_test@exe/main.c.o.d' -o 'juce_test@exe/main.c.o' -c ../main.c
cc: error: JUCE_MODULE_AVAILABLE_juce_analytics=1: No such file or directory
cc: error: LINUX=1: No such file or directory
ninja: build stopped: subcommand failed.

@mensinda mensinda added this to the 0.54.3 milestone Jun 13, 2020
@mensinda
Copy link
Member

OK, this only appears to be a problem with INTERFACE libraries, so I missed it in my first test.

This should be fixed now in #7309.

@mensinda
Copy link
Member

@ComradeStalin17 The cpp_std can be ignored most of the time, assuming your cpp_std of your root project is high enough.

It is just not that trivial to map every possible -std=c++<insert random 2 chars> compiler flag to one of the cpp_std choices meson knows of if there is not an exact match.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependency:cmake Issues related to `dependency` with the `cmake` method subprojects/wraps
Projects
None yet
Development

No branches or pull requests

3 participants