bneijt / ccbuild

C++ source scanning build utility
GNU General Public License v2.0
5 stars 3 forks source link

Trying to build ccbuild using python cxxbuild tool #34

Closed igormcoelho closed 9 months ago

igormcoelho commented 9 months ago

Hello, I'm professor in Brazil, so I spent many times having trouble with C/C++ students being unable to build basic programs... and nowadays, with more dependencies (such as fmt) and build systems (cmake, bazel, ), and package managers (vcpkg, conan, ...), everything gets much more complicated than in other recent languages, such as Rust. So, I tried to give such a similar experience to them, at least for reasonably simple projects.

I created a python project named cxxbuild/cxxdeps, that describes dependency file named cxxdeps, and a script named cxxbuild, that tries to automatically build a C++ software. It works for CMake and Bazel, currently.

So, I came here to try to build your ccbuild project using my cxxbuild python tool, and it almost did it automatically! If it works, it can be nice for you just to build your own software with a "pip install cxxbuild" and "cxxbuild ." commands :) But some things were unfortunately done manually...

These were the challenges I could find: 1) Missing description of C++ dependencies: I managed to learn that you need these dependencies (on Ubuntu Linux apt install flex; apt install libboost-all-dev; apt install gnutls-dev; apt install libbobcat-dev) so as the corresponding link options (bobcat gnutls fl) 2) Missing VERSION definition 3) Lack of understanding of how this FLEX works

The 1 and 2 were easy to fix, and I added these to my cxxdeps.toml description (of your dependencies). I wonder if VERSION could have some default value at least, to prevent needing to manually define it?

The 3 was more complicated, but I solved it with the following steps:

With these, all the 4 detected binaries were successfully built! I needed to manually remove "isBinTarget.cc" because your comment "int main(" broke my basic manual detection of main function :) But I'll fix it soon... at least for this case ;)

So, I wonder how could this FLEX step be properly done, without any manual works, like I did above. Thanks!

This is my cxxbuild project: https://github.com/manydeps/cxxbuild

igormcoelho commented 9 months ago

Ok, I realize now you already have a very compact CMakeLists.txt file, so it is not really necessary to use this cxxbuild tool here... but, in the end, it worked with few parameters: cxxbuild . --tests test --include src --include src/sourceScanner --c++20 Create cxxdeps.txt file locally:

bobcat
gnutls
fl
png
# apt install flex 
# apt install libboost-all-dev
# apt install gnutls-dev
# apt install libbobcat-dev
# libpng-dev

And then, just tweak the generated CMakeLists to include these lines:

find_package(FLEX)
FLEX_TARGET(SourceScanner "src/sourceScanner/lexer"  "src/sourceScanner/yylex.cc" )
# SOURCES BEGIN
${FLEX_SourceScanner_OUTPUTS}
# END OF FILE
add_definitions(-DVERSION="v2.0.7-39-gdf7b35c")

And that's it! It builds all available targets:

add_executable(ccbuild src/ccbuild.cc ${SOURCES})
add_executable(test src/string/test.cc ${SOURCES})
add_executable(test_system src/system/test_system.cc ${SOURCES})
add_executable(test2 src/fileSystem/test.cc ${SOURCES})
add_executable(argvtest_test test/argvtest.cc ${SOURCES})
add_executable(arguments_test test/arguments.cc ${SOURCES})
add_executable(include_test test/include.cc ${SOURCES})
add_executable(openmp_exceptions_test test/openmp_exceptions.cc ${SOURCES})
add_executable(parsetest_test test/parsetest.cpp ${SOURCES})
add_executable(zeroblock_mem_test test/zeroblock_mem.cc ${SOURCES})
add_executable(container_const_test test/container_const.cc ${SOURCES})
add_executable(attempt1_test test/attempt1.cc ${SOURCES})
add_executable(thread_test test/threading/thread.cc ${SOURCES})

Generated CMakeLists.txt is 277 lines long, so much bigger than yours, that has 16 lines... so I won't put it here :)

In any case, congratulations for your project, I had used it few times before, now I learned a little bit more on how it works.

bneijt commented 8 months ago

Thank you very much for taking the time to play around with my code and happy to hear it works!