cginternals / glbinding

A C++ binding for the OpenGL API, generated using the gl.xml specification.
https://glbinding.org
MIT License
831 stars 93 forks source link

Unable to build with Meson - use of `PRIVATE`/`PUBLIC` in `set()` #322

Closed Tachi107 closed 2 years ago

Tachi107 commented 3 years ago

It is currently impossible to compile the library with Meson as a CMake subproject.

This is caused by the usage of PRIVATE and PUBLIC when setting DEFAULT_COMPILE_OPTIONS in cmake/CompileOptions.cmake#L102. According to the documentation, the visibility keywords can't be used in set()

Here's the build log:

FAILED: CppSnake.p/main.cpp.o 
c++ -ICppSnake.p -I. -I.. -Isubprojects/glbinding/__CMake_build/source/include -I../subprojects/glbinding/__CMake_build/source/include -I../subprojects/glbinding/source/glbinding/include -Isubprojects/glbinding/__CMake_build/source/glbinding/include -I../subprojects/glbinding/__CMake_build/source/glbinding/include -I/usr/include -Isubprojects/glbinding/__CMake_build -I../subprojects/glbinding/__CMake_build -Isubprojects/glbinding -I../subprojects/glbinding -I../subprojects/glfw/include -I../subprojects/glfw/src -Isubprojects/glfw/__CMake_build/src -I../subprojects/glfw/__CMake_build/src -Isubprojects/glfw/__CMake_build -I../subprojects/glfw/__CMake_build -Isubprojects/glfw -I../subprojects/glfw -flto -Xclang -fcolor-diagnostics -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wnon-virtual-dtor -std=c++20 -g -fuse-ld=lld -Wno-unused-command-line-argument -DGLBINDING_STATIC_DEFINE -DSYSTEM_LINUX PRIVATE -Wall -Wextra -Wunused -Wreorder -Wignored-qualifiers -Wmissing-braces -Wreturn-type -Wswitch -Wswitch-default -Wuninitialized -Wmissing-field-initializers PUBLIC -MD -MQ CppSnake.p/main.cpp.o -MF CppSnake.p/main.cpp.o.d -o CppSnake.p/main.cpp.o -c ../main.cpp
clang: error: no such file or directory: 'PRIVATE'
clang: error: no such file or directory: 'PUBLIC'

Removing the keywords solves the issue

Tachi107 commented 3 years ago

After looking a bit more into this issue I noticed how DEFAULT_COMPILE_OPTIONS is simply treated as a string array that gets later passed into target_compile_options(), that indeed supports PRIVATE and PUBLIC. The issue here seems to be that Meson has some issues parsing compile options passed to target_compile_options() as a semicolon-separated list, and instead of seeing PRIVATE and PUBLIC as keywords it sees it as raw compile options.

One possible solution would be to split DEFAULT_COMPILE_OPTIONS into two variables, DEFAULT_COMPILE_OPTIONS_PRIVATE and _PUBLIC, or raising the minimum required CMake version to 3.1 so that defining PUBLIC flags in DEFAULT_COMPILE_OPTIONS will be no longer needed. (On this matter, CMake 3.5 or better is supported on all the maintained Linux distributions, and would be a safe version to require)