A simple script to create a Meson C++ project skeleton with Doxygen and gtest configured. The whole script can be found in this GitHub repo.
Usage:
./create_project
Usage: create_project PROJECT_ROOT_DIRECTORY [-f] Creates a directory 'PROJECT_ROOT_DIRECTORY' and populates it with some configuration files. By default *never* overwrite files, use the -f extra flag to force overwriting
To create a skeleton project in /tmp/MyProject
, run
./create_project /tmp/MyProject
Create directory /tmp/MyProject Create file /tmp/MyProject/meson.build Create directory /tmp/MyProject/src Create file /tmp/MyProject/src/meson.build Create directory /tmp/MyProject/src/MyProject Create file /tmp/MyProject/src/MyProject/meson.build Create file /tmp/MyProject/src/MyProject/hello.hpp Create file /tmp/MyProject/src/MyProject/hello.cpp Create directory /tmp/MyProject/subprojects Create file /tmp/MyProject/subprojects/gtest.wrap Create directory /tmp/MyProject/test Create file /tmp/MyProject/test/meson.build Create file /tmp/MyProject/test/hello.cpp Create directory /tmp/MyProject/bin Create file /tmp/MyProject/bin/meson.build Create file /tmp/MyProject/bin/hello.cpp Create directory /tmp/MyProject/sandbox Create file /tmp/MyProject/sandbox/meson.build Create file /tmp/MyProject/sandbox/hello.cpp Create directory /tmp/MyProject/examples Create file /tmp/MyProject/examples/meson.build Create file /tmp/MyProject/examples/hello.cpp Create directory /tmp/MyProject/doc Create directory /tmp/MyProject/doc/figures Create file /tmp/MyProject/doc/meson.build Create file /tmp/MyProject/doc/Doxyfile.in Create file /tmp/MyProject/doc/bibliography.bib
You get a basic Meson project with the following directory hierarchy:
+ meson.build <- root meson file + src/ + MyProject/ <- your "MyProject" library (installed, scanned by Doxygen) + hello.cpp + hello.hpp + meson.build + meson.build + bin/ <- binaries (installed, scanned by Doxygen) + meson.build + hello.cpp + sandbox/ <- "sandbox" binaries (not installed, not scanned by Doxygen) + meson.build + hello.cpp + examples/ <- "examples" binaries (not installed, Doxygen examples dir) + meson.build + hello.cpp + test/ <- unit tests (not installed) + meson.build + hello.cpp + doc/ + meson.build + bibliography.bib <- doxygen + bibliography file (installed) + Doxyfile.in + subprojects/ <- subprojects, here gtest (not installed) + gtest.wrap
To create your project build directory with /tmp/InstallDirectory
as
installation directory run:
cd /tmp/MyProject
meson build --prefix=/tmp/InstallDirectory
The Meson build system Version: 0.49.2 Source dir: /tmp/MyProject Build dir: /tmp/MyProject/build Build type: native build Project name: MyProject Project version: 0.0.1 Native C++ compiler: ccache c++ (gcc 8.3.0 "c++ (Debian 8.3.0-6) 8.3.0") Build machine cpu family: x86_64 Build machine cpu: x86_64 Downloading gtest source from https://github.com/google/googletest/archive/release-1.8.0.zip Downloading file of unknown size. Downloading gtest patch from https://wrapdb.mesonbuild.com/v1/projects/gtest/1.8.0/5/get_zip Download size: 2084 Downloading: .......... | |Executing subproject gtest | |Project name: gtest |Project version: 1.8.0 |Native C++ compiler: ccache c++ (gcc 8.3.0 "c++ (Debian 8.3.0-6) 8.3.0") |Dependency threads found: YES |Dependency threads found: YES (cached) |Dependency threads found: YES (cached) |Dependency threads found: YES (cached) |Build targets in project: 0 | |Subproject gtest finished. Program doxygen found: YES (/usr/bin/doxygen) Program dot found: YES (/usr/bin/dot) Configuring Doxyfile using configuration Build targets in project: 6 Found ninja-1.8.2 at /usr/bin/ninja
To compile your project (with its doxygen documentation) type:
cd build
ninja
[1/14] Compiling C++ object 'src/MyProject/63d4f26@@MyProject@sha/hello.cpp.o'. [2/14] Compiling C++ object 'sandbox/b7ad567@@hello@exe/hello.cpp.o'. [3/14] Compiling C++ object 'test/9f86d08@@hello_exe@exe/.._subprojects_googletest-release-1.8.0_googletest_src_gtest_main.cc.o'. [4/14] Compiling C++ object 'test/9f86d08@@hello_exe@exe/hello.cpp.o'. [5/14] Compiling C++ object 'bin/51a1f05@@hello@exe/hello.cpp.o'. [6/14] Compiling C++ object 'test/9f86d08@@hello_exe@exe/.._subprojects_googletest-release-1.8.0_googletest_src_gtest-all.cc.o'. [7/14] Compiling C++ object 'examples/c590b3c@@hello@exe/hello.cpp.o'. [8/14] Linking target src/MyProject/libMyProject.so. [9/14] Generating doc with a custom command. warning: ignoring unknown tag `y' at line 2277, file doc/Doxyfile Searching for include files... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Searching for example files... Searching for files in directory /tmp/MyProject/examples Searching for images... Searching for files in directory /tmp/MyProject/doc/figures Searching for dot files... Searching for msc files... Searching for dia files... Searching for files to exclude Searching INPUT for files to process... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Reading and parsing tag files Parsing files Preprocessing /tmp/MyProject/src/MyProject/hello.cpp... Parsing file /tmp/MyProject/src/MyProject/hello.cpp... Preprocessing /tmp/MyProject/src/MyProject/hello.hpp... Parsing file /tmp/MyProject/src/MyProject/hello.hpp... Preprocessing /tmp/MyProject/bin/hello.cpp... Parsing file /tmp/MyProject/bin/hello.cpp... Building group list... Building directory list... Building namespace list... Building file list... Building class list... Associating documentation with classes... Computing nesting relations for classes... Building example list... Searching for enumerations... Searching for documented typedefs... Searching for members imported via using declarations... Searching for included using directives... Searching for documented variables... Building interface member list... Building member list... Searching for friends... Searching for documented defines... Computing class inheritance relations... Computing class usage relations... Flushing cached template relations that have become invalid... Computing class relations... Add enum values to enums... Searching for member function documentation... Creating members for template instances... Building page list... Search for main page... Computing page relations... Determining the scope of groups... Sorting lists... Freeing entry tree Determining which enums are documented Computing member relations... Building full member lists recursively... Adding members to member groups. Computing member references... Inheriting documentation... Generating disk names... Adding source references... Adding xrefitems... Sorting member lists... Generating citations page... Counting data structures... Resolving user defined references... Finding anchors and sections in the documentation... Transferring function references... Combining using relations... Adding members to index pages... Generating style sheet... Generating search indices... Generating example documentation... Generating file sources... Generating code for file hello.hpp... Generating file documentation... Generating docs for file hello.cpp... Generating docs for file hello.hpp... Generating page documentation... Generating docs for page citelist... Generating group documentation... Generating class documentation... Generating namespace index... Generating graph info page... Generating directory documentation... Generating index page... Generating page index... Generating module index... Generating namespace index... Generating namespace member index... Generating annotated compound index... Generating alphabetical compound index... Generating hierarchical class index... Generating member index... Generating file index... Generating file member index... Generating example index... finalizing index lists... writing tag file... Running dot... Running dot for graph 1/1 lookup cache used 5/65536 hits=10 misses=5 finished... [10/14] Generating symbol file 'src/MyProject/63d4f26@@MyProject@sha/libMyProject.so.symbols'. [11/14] Linking target bin/hello. [12/14] Linking target sandbox/hello. [13/14] Linking target examples/hello. [14/14] Linking target test/hello_exe.
Note: You can visualize the generated documentation with:
chromium doc/html/index.html
To run unit tests, run:
ninja test
[1/2] Generating doc with a custom command. warning: ignoring unknown tag `y' at line 2277, file doc/Doxyfile Searching for include files... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Searching for example files... Searching for files in directory /tmp/MyProject/examples Searching for images... Searching for files in directory /tmp/MyProject/doc/figures Searching for dot files... Searching for msc files... Searching for dia files... Searching for files to exclude Searching INPUT for files to process... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Reading and parsing tag files Parsing files Preprocessing /tmp/MyProject/src/MyProject/hello.cpp... Parsing file /tmp/MyProject/src/MyProject/hello.cpp... Preprocessing /tmp/MyProject/src/MyProject/hello.hpp... Parsing file /tmp/MyProject/src/MyProject/hello.hpp... Preprocessing /tmp/MyProject/bin/hello.cpp... Parsing file /tmp/MyProject/bin/hello.cpp... Building group list... Building directory list... Building namespace list... Building file list... Building class list... Associating documentation with classes... Computing nesting relations for classes... Building example list... Searching for enumerations... Searching for documented typedefs... Searching for members imported via using declarations... Searching for included using directives... Searching for documented variables... Building interface member list... Building member list... Searching for friends... Searching for documented defines... Computing class inheritance relations... Computing class usage relations... Flushing cached template relations that have become invalid... Computing class relations... Add enum values to enums... Searching for member function documentation... Creating members for template instances... Building page list... Search for main page... Computing page relations... Determining the scope of groups... Sorting lists... Freeing entry tree Determining which enums are documented Computing member relations... Building full member lists recursively... Adding members to member groups. Computing member references... Inheriting documentation... Generating disk names... Adding source references... Adding xrefitems... Sorting member lists... Generating citations page... Counting data structures... Resolving user defined references... Finding anchors and sections in the documentation... Transferring function references... Combining using relations... Adding members to index pages... Generating style sheet... Generating search indices... Generating example documentation... Generating file sources... Generating code for file hello.hpp... Generating file documentation... Generating docs for file hello.cpp... Generating docs for file hello.hpp... Generating page documentation... Generating docs for page citelist... Generating group documentation... Generating class documentation... Generating namespace index... Generating graph info page... Generating directory documentation... Generating index page... Generating page index... Generating module index... Generating namespace index... Generating namespace member index... Generating annotated compound index... Generating alphabetical compound index... Generating hierarchical class index... Generating member index... Generating file index... Generating file member index... Generating example index... finalizing index lists... writing tag file... Running dot... lookup cache used 5/65536 hits=10 misses=5 finished... [1/2] Running all tests. 1/1 hello_test OK 0.01 s Ok: 1 Expected Fail: 0 Fail: 0 Unexpected Pass: 0 Skipped: 0 Timeout: 0 Full log written to /tmp/MyProject/build/meson-logs/testlog.txt
Finally, if you want to install your project, run:
ninja install
[1/2] Generating doc with a custom command. warning: ignoring unknown tag `y' at line 2277, file doc/Doxyfile Searching for include files... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Searching for example files... Searching for files in directory /tmp/MyProject/examples Searching for images... Searching for files in directory /tmp/MyProject/doc/figures Searching for dot files... Searching for msc files... Searching for dia files... Searching for files to exclude Searching INPUT for files to process... Searching for files in directory /tmp/MyProject/src/MyProject Searching for files in directory /tmp/MyProject/bin Reading and parsing tag files Parsing files Preprocessing /tmp/MyProject/src/MyProject/hello.cpp... Parsing file /tmp/MyProject/src/MyProject/hello.cpp... Preprocessing /tmp/MyProject/src/MyProject/hello.hpp... Parsing file /tmp/MyProject/src/MyProject/hello.hpp... Preprocessing /tmp/MyProject/bin/hello.cpp... Parsing file /tmp/MyProject/bin/hello.cpp... Building group list... Building directory list... Building namespace list... Building file list... Building class list... Associating documentation with classes... Computing nesting relations for classes... Building example list... Searching for enumerations... Searching for documented typedefs... Searching for members imported via using declarations... Searching for included using directives... Searching for documented variables... Building interface member list... Building member list... Searching for friends... Searching for documented defines... Computing class inheritance relations... Computing class usage relations... Flushing cached template relations that have become invalid... Computing class relations... Add enum values to enums... Searching for member function documentation... Creating members for template instances... Building page list... Search for main page... Computing page relations... Determining the scope of groups... Sorting lists... Freeing entry tree Determining which enums are documented Computing member relations... Building full member lists recursively... Adding members to member groups. Computing member references... Inheriting documentation... Generating disk names... Adding source references... Adding xrefitems... Sorting member lists... Generating citations page... Counting data structures... Resolving user defined references... Finding anchors and sections in the documentation... Transferring function references... Combining using relations... Adding members to index pages... Generating style sheet... Generating search indices... Generating example documentation... Generating file sources... Generating code for file hello.hpp... Generating file documentation... Generating docs for file hello.cpp... Generating docs for file hello.hpp... Generating page documentation... Generating docs for page citelist... Generating group documentation... Generating class documentation... Generating namespace index... Generating graph info page... Generating directory documentation... Generating index page... Generating page index... Generating module index... Generating namespace index... Generating namespace member index... Generating annotated compound index... Generating alphabetical compound index... Generating hierarchical class index... Generating member index... Generating file index... Generating file member index... Generating example index... finalizing index lists... writing tag file... Running dot... lookup cache used 5/65536 hits=10 misses=5 finished... [1/2] Installing files. Installing src/MyProject/libMyProject.so to /tmp/InstallDirectory/lib/x86_64-linux-gnu Installing bin/hello to /tmp/InstallDirectory/bin Installing /tmp/MyProject/build/doc/html/a00005.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/tab_h.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/sync_on.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/graph_legend.md5 to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/pages.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/jquery.js to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/menu.js to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/folderclosed.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/dir_12739b51ecd9f955b0759ea118dd308c.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/nav_f.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/tab_s.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/splitbar.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/graph_legend.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/closed.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/bdwn.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/a00015.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/tabs.css to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/doxygen.css to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/index.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/tab_a.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/open.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/menudata.js to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/graph_legend.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/nav_h.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/a00012.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/bc_s.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/doxygen.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/nav_g.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/dynsections.js to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/dir_2ea30aa2956a8db99dd22aa5e597f384.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/files.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/sync_off.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/folderopen.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/a00005_source.html to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/tab_b.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/doc.png to /tmp/InstallDirectory/share/doc/html Installing /tmp/MyProject/build/doc/html/search/files_1.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/all_1.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/search_r.png to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/all_0.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/close.png to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/search.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/search_l.png to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/files_0.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/searchdata.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/nomatches.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/pages_0.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/all_0.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/files_1.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/mag_sel.png to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/search.css to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/pages_0.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/all_1.html to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/search_m.png to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/build/doc/html/search/files_0.js to /tmp/InstallDirectory/share/doc/html/search Installing /tmp/MyProject/src/MyProject/hello.hpp to /tmp/InstallDirectory/include/MyProject
cat /tmp/MyProject/src/MyProject/hello.hpp
/// @file /// @brief Hello lib file include <string> namespace MyProject { /// @brief A function /// /// A bibtex reference example @cite pakkanen_meson_build_system /// /// Usage example @include hello.cpp std::string hello(); }
cat /tmp/MyProject/src/MyProject/hello.cpp
include "hello.hpp" namespace MyProject { std::string hello() { return "Hello MyProject"; }; }
cat /tmp/MyProject/test/hello.cpp
include "MyProject/hello.hpp" include <gtest/gtest.h> using namespace MyProject; TEST(Hello, demo) { ASSERT_EQ(hello(),"Hello MyProject"); }
cat /tmp/MyProject/bin/hello.cpp
/// @file /// @brief Hello executable file include "MyProject/hello.hpp" include <iostream> using namespace MyProject; int main() { std::cout << hello() << " from bin/ " << std::endl; }
cat /tmp/MyProject/sandbox/hello.cpp
/// @file /// @brief Hello example file include "MyProject/hello.hpp" include <iostream> using namespace MyProject; int main() { std::cout << hello() << " from sandbox/ " << std::endl; }
cat /tmp/MyProject/examples/hello.cpp
/// @file /// @brief Hello example file include "MyProject/hello.hpp" include <iostream> using namespace MyProject; int main() { std::cout << hello() << " from examples/ " << std::endl; }
Some Meson official site links: