diff options
| author | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-02 19:50:11 +0200 | 
|---|---|---|
| committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2022-05-26 18:41:21 +0200 | 
| commit | 1a8d7736a99c974462310e4efea2f47713255a8b (patch) | |
| tree | 248485bc8774443190081ca9442acb23bf89f153 | |
| parent | 8b65d0eb2815576780c57df428c1faf23fe75068 (diff) | |
Moc generation through ctor.
| -rw-r--r-- | ctor.cc | 82 | 
1 files changed, 73 insertions, 9 deletions
| @@ -1,12 +1,53 @@  // -*- c++ -*-  #include <libctor.h> +#include <filesystem> +#include <iostream>  namespace  { -BuildConfigurations myConfigs() +std::vector<Source> eval_mocs(const std::string& path, +                              const std::vector<std::pair<std::string, std::string>>& moc_list)  { -	return +	std::vector<Source> sources; +	for(const auto& moc : moc_list)  	{ +		std::filesystem::path input(moc.first); +		std::filesystem::path output(moc.second); + +		std::filesystem::path fspath(path); + +		if(!std::filesystem::exists(fspath / input)) +		{ +			std::cerr << "Missing moc input file: " << input.string() << '\n'; +			exit(1); +		} + +		if(!std::filesystem::exists(path / output) || +		   std::filesystem::last_write_time(path / input) > +		   std::filesystem::last_write_time(path / output)) +		{ +			std::string cmd = "cd \"" + path + "\"; moc "; +			cmd += "-o \"" + output.string() + "\" \"" + input.string() + "\""; +			std::cerr << cmd << "\n"; +			auto ret = system(cmd.data()); +			if(ret != 0) +			{ +				std::cerr << "moc generation failed: " << cmd << '\n'; +				exit(ret); +			} +		} +		sources.push_back((path / output).string()); +	} + +	return sources; +} + +BuildConfigurations myConfigs() +{ +	// +	// Qookie-cast client +	// +	BuildConfiguration qookie =  		{  			.target = "qookie",  // output filename  			.sources = { @@ -15,11 +56,8 @@ BuildConfigurations myConfigs()  				"src/database_gourmet.cc",  				"src/database_krecipes.cc",  				"src/mainwindow.cc", -				"src/moc_mainwindow.cc",  				"src/viewer.cc", -				"src/moc_viewer.cc",  				"src/client.cc", -				"src/moc_client.cc",  			},  			.flags = {  				.cxxflags = { @@ -40,12 +78,27 @@ BuildConfigurations myConfigs()  					"-lsqlite3",  				}  			}, -		}, +		}; +	std::vector<Source> qookie_mocs = +		eval_mocs("src", +		          { +		           { "mainwindow.h", "moc_mainwindow.cc"}, +		           { "viewer.h",     "moc_viewer.cc"}, +		           { "client.h",     "moc_client.cc"}, +		          }); +	for(const auto& moc : qookie_mocs) +	{ +		qookie.sources.push_back(moc); +	} + +	// +	// Qookie-cast client +	// +	BuildConfiguration qookie_cast_client =  		{  			.target = "qookie-cast-client",  // output filename  			.sources = {  				"src/qookie-cast-client.cc", -				"src/moc_qookie-cast-client.cc",  			},  			.flags = {  				.cxxflags = { @@ -67,8 +120,19 @@ BuildConfigurations myConfigs()  //					"-lQt5WebKit",  				}  			}, -		} -	}; +		}; + +	std::vector<Source> qookie_cast_client_mocs = +		eval_mocs("src", +		          { +		           { "qookie-cast-client.h", "moc_qookie-cast-client.cc"}, +		          }); +	for(const auto& moc : qookie_cast_client_mocs) +	{ +		qookie_cast_client.sources.push_back(moc); +	} + +	return {qookie, qookie_cast_client};  }  } | 
