Skip to content

Commit

Permalink
perfect for ccbuild usecase
Browse files Browse the repository at this point in the history
  • Loading branch information
igormcoelho committed May 21, 2024
1 parent 8c9f891 commit 523313c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 16 deletions.
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,15 @@ Hopefully, when this project is fully finished, C++ will be a better place for a

### Case of Study

In order to check the capabilities of cxxbuild, it was used to build the C/C++ ccbuild tool.
Unfortunately, few tweaks were necessary in the generated CMakeLists, due to FLEX dependency,
but it was quite easy on general. See [Issue 34 on ccbuild project](https://github.com/bneijt/ccbuild/issues/34)

General instructions:
- Create `cxxdeps.txt` file:
A very interesting case of study is the use of cxxbuild to build the C/C++ ccbuild tool.
It is currently very easy to build it, using the following cxxdeps file:

```
bobcat
gnutls
fl
png
FLEX == * [ ] local * _ false patch_flex.txt
!std c++20
!tests test
!include "src"
Expand All @@ -271,10 +268,10 @@ png
# apt install libpng-dev
```

- Use the following build script: `cxxbuild . --tests test --include src --include src/sourceScanner --c++20` (or just `cxxbuild`, since build options will come directly from *cxxdeps.txt*)
- On may also use the following build script: `cxxbuild . --tests test --include src --include src/sourceScanner --c++20` (or just `cxxbuild`, since build options will come directly from *cxxdeps.txt*)
- This line will be added automatically to CMakeLists: `add_definitions(-DVERSION="v2.0.7-39-gdf7b35c")`
- This line will be added automatically to SOURCES: `${FLEX_SourceScanner_OUTPUTS}`
- Add these two lines before the SOURCES:
- These two lines will be put before the SOURCES:

```
find_package(FLEX)
Expand Down
14 changes: 11 additions & 3 deletions cxxbuild/cxxbuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ def get_cmakelists_from_cxxdeps(root_path, cmakelists, INCLUDE_DIRS, src_main, s
# todo: check libraries as well
# todo: attach it to libraries, binaries and test binaries, if mode is *
if special != "":
cmakelists.append(special)
# load patch file and append it
with open(root_path+'/'+special, 'r') as fdx:
patches=fdx.readlines()
for p_line in patches:
cmakelists.append(p_line)
continue
# end if local
print("cxxdeps error: build type '"+pkg_manager+"' unknown or not supported!")
Expand Down Expand Up @@ -1132,8 +1136,12 @@ def run_build(root_path, use_cmake, use_bazel, cppstd, search_src, search_tests,
# If someone has a function "xxxmain(" it can currently break.
entrypoint = "main("
print("checking entrypoint:", entrypoint)
if entrypoint in fd.read():
src_main[file_path] = (root, file_name)
all_lines=fd.readlines()
for l in all_lines:
# avoid commented lines (small improvement)
l2 = l.strip()
if entrypoint in l2 and l2[0] != "/" and l2[1] != "/":
src_main[file_path] = (root, file_name)
# end-for src_path
# end-for src_paths

Expand Down
6 changes: 2 additions & 4 deletions usecases/ccbuild/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ Steps:
- Unzip it: `unzip main.zip`
- Manually install dependencies from `cxxdeps.template.txt`
- Copy cxxdeps: `cp cxxdeps.template.txt ccbuild-main/cxxdeps.txt`
- Invoke cxxbuild on ccbuild-main folder: `cxxbuild ccbuild-main`
- Manually fix the FLEX on generated CMakeLists, as discussed before, by adding two extra lines on cmakelists (see example)
- Manually invoke cmake to finish build: `cd ccbuild-main/build/ && cmake .. -GNinja && ninja`
- Still not fully automated, but it works!
- Copy flex patch file: `cp patch_flex.txt ccbuild-main/`
- Invoke cxxbuild on ccbuild-main folder and be happy: `cxxbuild ccbuild-main`

See issue: https://github.com/bneijt/ccbuild/issues/34
2 changes: 1 addition & 1 deletion usecases/ccbuild/cxxdeps.template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ bobcat
gnutls
fl
png
FLEX == * [ ] local * _ false patch_flex.txt
!std c++20
!tests test
!include "src"
!include "src/sourceScanner"
!define VERSION="v2.0.7-39-gdf7b35c"
!extrasrc ${FLEX_SourceScanner_OUTPUTS}
!extrasrc src/source/isBinTarget.cc
# apt install flex
# apt install libboost-all-dev
# apt install gnutls-dev
Expand Down
1 change: 1 addition & 0 deletions usecases/ccbuild/patch_flex.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FLEX_TARGET(SourceScanner "src/sourceScanner/lexer" "src/sourceScanner/yylex.cc" )

0 comments on commit 523313c

Please sign in to comment.