forked from shawwn/scrap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmake-gen-globs
executable file
·81 lines (61 loc) · 1.88 KB
/
cmake-gen-globs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/bash
# Invoke this (monstrosity) as follows:
#
# brew install clion
#
# git clone https://github.com/tensorflow/tensorflow
# cd tensorflow
# name="tensorflow" cmake-gen-globs > CMakeLists.txt
# clion .
#
# you'll eventually discover that you need to add extra include
# directories for CLion to function properly. For example,
# Emacs has code like #include <config.h>, and config.h
# lives underneath ./src.
#
# Here's how to generate the emacs CMakeLists.txt I currently use:
#
# git clone https://github.com/emacs-mirror/emacs
# cd emacs
# name="emacs" cmake-gen-globs src lib > CMakeLists.txt
# clion .
set -e
export name="${name:-$(basename "$(pwd)")}"
export src="${src:-.}"
export extra="${extra:-*.c}"
cat <<EOF
cmake_minimum_required(VERSION 3.14)
project($name)
set(CMAKE_CXX_STANDARD 14)
include_directories(\${CMAKE_SOURCE_DIR})
EOF
for include_directory in "$@"
do
cat <<EOF
include_directories(\${CMAKE_SOURCE_DIR}/${include_directory})
EOF
done
cat <<EOF
EOF
for op in and or
do
#rgfiles -tc -tcpp -tobjc . . "$@" \
find $src -type f -name '*.c' -or -name '*.cc' -or -name '*.cpp' -or -name '*.cxx' -or -name '*.mm' -or -name '*.m' -or -name "$extra" \
| grep -v '/cmake-build-' | sort | rg '[/][^/]+[.]([a-zA-Z]+)' --replace '/*.$1' | sort | uniq | python3 -c 'import sys, os; [print(f"{x}", flush=True) for x in sys.stdin for x in [x.strip().lstrip("./")] for x in [(os.environ["name"]+"_"+"".join([c if c.isalnum() else "_" for c in x]), x)] for (key, path) in [x] for x in [rf"""file(GLOB {key} "${{CMAKE_SOURCE_DIR}}/{path}")"""] for x in [" ${"+key+"}"] '$op' [x]]'
case $op in
and)
cat <<EOF
add_library( # Sets the name of the library.
${name}
# Sets the library as a shared library.
SHARED
EOF
;;
esac
done
cat <<EOF
)
target_link_libraries( # Specifies the target library.
${name}
)
EOF