use 'source_group' generate the Xcode project can't jump the right directory path - cmake

I used the CMake to build an iOS XCode project, I have multiple level source code, so I use 'source_group' to organize them, here is my CMake code
file(GLOB_RECURSE MODULE_DEMO_DIR_FILES
"${MODULE_DEMO_DIR}/*.h"
"${MODULE_DEMO_DIR}/*.m"
"${MODULE_DEMO_DIR}/*.c"
"${MODULE_DEMO_DIR}/*.cc"
"${MODULE_DEMO_DIR}/*.cpp"
"${MODULE_DEMO_DIR}/info.plist"
"${MODULE_DEMO_DIR}/LaunchScreen.storyboard"
"${MODULE_DEMO_DIR}/*.entitlements"
)
foreach(file IN LISTS MODULE_DEMO_DIR_FILES)
message(DEBUG "file:${file}")
get_filename_component(fileDirectory ${file} DIRECTORY)
include_directories(${fileDirectory})
endforeach()
set(${MODULE_DEMO_SOURCES} ${MODULE_DEMO_DIR_FILES} PARENT_SCOPE)
source_group(TREE ${MODULE_DEMO_DIR} FILES ${MODULE_DEMO_DIR_FILES})
when I select any directory and right-click and select 'show in Finder', it does not jump right directory, in the xcodeproj file, I find the directory PBXGroup is this:
8CD0C75957674E25982ACF10 /* IQTextView */ = {
isa = PBXGroup;
children = (
8D7EEDCDA3CC4AA6A444A78F /* /Users/lee/Desktop/xx1/demo/company/xx2/xx3/demo/Vendor/IQKeyboardManager/IQTextView/IQTextView.h */,
F54B85341C9A4BC7BD92320D /* /Users/lee/Desktop/xx1/demo/company/xx2/xx3/demo/Vendor/IQKeyboardManager/IQTextView/IQTextView.m */,
);
name = IQTextView;
sourceTree = "<group>";
};
when I change the "name = IQTextView;" to "path = IQTextView;",it works!
my question is:
how let the PBXGroup use 'path' instead of 'name' when using CMake, so that I can jump to the true path when clicking "show in Finder" at a directory in XCode project?

Related

Converting a meson.build library to CMakeLists

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?

Build a CMake project with Nix

I'm trying to make a derivation from fokus (a KDE plasmoid).
I have a default.nix which looks like:
{ mkDerivation, lib, fetchFromGitLab, cmake, extra-cmake-modules
, plasma-framework
, qt5 }:
let
version = "1.5.4";
repo = fetchFromGitLab {
owner = "divinae";
repo = "focus-plasmoid";
rev = "v${version}";
sha256 = "19nndmqfzdcg7lzcifxa17m2mx85dlf4m2wxzr72gf78h4yj0ahv";
};
in
mkDerivation rec {
inherit version;
pname = "fokus";
src = "${repo}/packages";
dontUnpack = true;
buildInputs = [
plasma-framework
qt5.qtbase
];
nativeBuildInputs = [ cmake extra-cmake-modules ];
meta = with lib; {
description = "Simple pomodoro timer plasmoid";
homepage = "https://store.kde.org/p/1308861/";
license = licenses.gpl3Only;
maintainers = with maintainers; [ ];
platforms = platforms.unix;
};
}
I also added to all-packages:
fokus-plasma-applet = libsForQt5.callPackage ../applications/misc/fokus-plasma-applet { };
The thing is, I have only find few examples in nixpkgs, and I do not see what to do with this error (since CMakeLists.txt is effectively in /package):
building '/nix/store/c21h5667abmj4v0ci4n51ckvkxvc23gk-fokus-1.5.4.drv'...
qtPreHook
patching sources
configuring
fixing cmake files...
cmake flags: -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON -DCMAKE_BUILD_TYPE=Release -DCMAKE_SKIP_BUILD_RPATH=ON -DBUILD_TESTING=OFF -DCMAKE_INSTALL_LOCALEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/locale -DCMAKE_INSTALL_LIBEXECDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/libexec -DCMAKE_INSTALL_LIBDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DCMAKE_INSTALL_DOCDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/doc/fokus -DCMAKE_INSTALL_INFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/info -DCMAKE_INSTALL_MANDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/man -DCMAKE_INSTALL_OLDINCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DCMAKE_INSTALL_INCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DCMAKE_INSTALL_SBINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/sbin -DCMAKE_INSTALL_BINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/bin -DCMAKE_INSTALL_NAME_DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DCMAKE_POLICY_DEFAULT_CMP0025=NEW -DCMAKE_OSX_SYSROOT= -DCMAKE_FIND_FRAMEWORK=LAST -DCMAKE_STRIP=/nix/store/4g5fidyk19akng9n91cql60ylrjq93s6-gcc-wrapper-10.3.0/bin/strip -DCMAKE_RANLIB=/nix/store/ffcrrgb6k5h7crr93dj90bi9fy1jvj16-binutils-2.35.1/bin/ranlib -DCMAKE_AR=/nix/store/ffcrrgb6k5h7crr93dj90bi9fy1jvj16-binutils-2.35.1/bin/ar -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_INSTALL_PREFIX=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4 -DKDE_INSTALL_EXECROOTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4 -DKDE_INSTALL_BINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/bin -DKDE_INSTALL_SBINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/sbin -DKDE_INSTALL_LIBDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib -DKDE_INSTALL_LIBEXECDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/libexec -DKDE_INSTALL_CMAKEPACKAGEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/cmake -DKDE_INSTALL_INCLUDEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/include -DKDE_INSTALL_LOCALSTATEDIR=/var -DKDE_INSTALL_DATAROOTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share -DKDE_INSTALL_DATADIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share -DKDE_INSTALL_DOCBUNDLEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/doc/HTML -DKDE_INSTALL_KCFGDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/config.kcfg -DKDE_INSTALL_KCONFUPDATEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kconf_update -DKDE_INSTALL_KSERVICES5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kservices5 -DKDE_INSTALL_KSERVICETYPES5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kservicetypes5 -DKDE_INSTALL_KXMLGUI5DIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/kxmlgui5 -DKDE_INSTALL_KNOTIFY5RCDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/knotifications5 -DKDE_INSTALL_ICONDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/icons -DKDE_INSTALL_LOCALEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/locale -DKDE_INSTALL_SOUNDDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/sounds -DKDE_INSTALL_TEMPLATEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/templates -DKDE_INSTALL_WALLPAPERDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/wallpapers -DKDE_INSTALL_APPDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/applications -DKDE_INSTALL_DESKTOPDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/desktop-directories -DKDE_INSTALL_MIMEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/mime/packages -DKDE_INSTALL_METAINFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/appdata -DKDE_INSTALL_MANDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/man -DKDE_INSTALL_INFODIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/info -DKDE_INSTALL_DBUSDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1 -DKDE_INSTALL_DBUSINTERFACEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/interfaces -DKDE_INSTALL_DBUSSERVICEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/services -DKDE_INSTALL_DBUSSYSTEMSERVICEDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/share/dbus-1/system-services -DKDE_INSTALL_SYSCONFDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc -DKDE_INSTALL_CONFDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc/xdg -DKDE_INSTALL_AUTOSTARTDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/etc/xdg/autostart -DKDE_INSTALL_QTPLUGINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/plugins -DKDE_INSTALL_PLUGINDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/plugins -DKDE_INSTALL_QMLDIR=/nix/store/5rdpaqmcj9hrpwdcnprr0zm51659mp08-fokus-1.5.4/lib/qt-5.15.2/qml
CMake Error: The source directory "/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
builder for '/nix/store/c21h5667abmj4v0ci4n51ckvkxvc23gk-fokus-1.5.4.drv' failed with exit code 1
cannot build derivation '/nix/store/b9jhnh8bix892wql3qifvgf742lq41v9-system-path.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/3n3mwi7vqmnkng6r8kpa9881xdgcd253-nixos-system-looping-21.11pre328987.c935f5e0add.drv': 1 dependencies couldn't be built
error: build of '/nix/store/3n3mwi7vqmnkng6r8kpa9881xdgcd253-nixos-system-looping-21.11pre328987.c935f5e0add.drv' failed

Is there QMake analogue for ".." from bash?

I'm writing a unit test using QtTest framework. I have a .pro file representing test project where i want to specify a relative path to the source files i want to test with INCLUDEPATH keyword. The source files are in the source folder, which is 2 levels above the .pro file in folder hierarchy. So, if i were to get there with bash i would go with cd .. then cd .. then cd source. I tried INCLUDEPATH += $$PWD/../../source, but this doesn't seem to work. I also couldn't find any related info in Qt docs.
How can i achieve the behaviour i want from qmake? Any help would be great.
There is a builtin (replace) function called clean_path. Documented here.
The following code did the trick for me:
defineReplace(cleanPath) {
win32:1 ~= s|\\\\|/|g
contains(1, ^/.*):pfx = /
else:pfx =
segs = $$split(1, /)
out =
for(seg, segs) {
equals(seg, ..):out = $$member(out, 0, -2)
else:!equals(seg, .):out += $$seg
}
win32:return($$join(out, \\, $$pfx))
return($$join(out, /, $$pfx))
}
srs_path = $$_PRO_FILE_PWD_/../../source
srs_path_clean = $$cleanPath($$srs_path)
INCLUDEPATH += $$srs_path_clean

Using #BASENAME# with install_dir of custom_target() in Meson

#BASENAME# does not appear to work in the install_dir: parameter of the Meson custom_target() function.
protoc = find_program('protoc')
protobuf_sources= [
'apples.proto',
'oranges.proto',
'pears.proto'
]
protobuf_generated_go = []
foreach protobuf_definition : protobuf_sources
protobuf_generated_go += custom_target('go_' + protobuf_definition,
command: [protoc, '--proto_path=#CURRENT_SOURCE_DIR#', '--go_out=paths=source_relative:#OUTDIR#', '#INPUT#'],
input: protobuf_definition,
output: '#BASENAME#.pb.go',
install: true,
install_dir: 'share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/'
)
endforeach
I need the generated files to end up in at directory based on the basename of the input file:
share/gocode/src/github.com/foo/bar/protobuf/go/apples/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/oranges/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/pears/pears.pb.go
If I use #BASENAME# in install_dir: to try and create the directory needed, it does not expand, and instead just creates a literal '#BASENAME#' directory.
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/apples.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/oranges.pb.go
share/gocode/src/github.com/foo/bar/protobuf/go/#BASENAME#/pears.pb.go
How can the required installed directory location based on the basename be achieved?
(just 3 files in the above example, I actually have 30+ files)
Yes, it looks as there is no support for placeholders like BASENAME for install_dir parameter since this feature aims at file names not directories. But you can process iterator that is string in a loop:
foreach protobuf_definition : protobuf_sources
...
install_dir: '.../go/#0#'.format(protobuf_definition.split('.')[0])
endforeach

How to manually set a CMake path variable to NOTFOUND?

I'm hardcoding a library path before hand and want to set the path to NOTFOUND manually if the file doesn't exist.
set(MY_LIB "path that doesn't exist")
if(NOT EXISTS "${MY_LIB}")
message("not found")
// set it back to NOTFOUND ??
endif()
if (MY_LIB)
// set flags
endif()
How to manually set a CMake path variable to NOTFOUND?
Just set it to the string:
set(MY_LIB "NOTFOUND")