WinToast icon indicating copy to clipboard operation
WinToast copied to clipboard

Build project with cmake

Open kenkit opened this issue 6 years ago • 19 comments

Build the project using cmake instead of Visual Studio Project files. This means users can generate any project file

kenkit avatar Jul 24 '19 08:07 kenkit

Now it should be possible to add project to other projects using cmake easily.

kenkit avatar Jul 24 '19 09:07 kenkit

I have nothing against cmake, actually I do use it in several projects.

However I see two issues in this PR:

  • The console-example was developed for the project git-for-windows originally. The principal developer wrote it using VS tools, so I guess they are not using cmake. Many Windows developer do not use cmake and are familiar with VS projects, so I don't see the point of removing the VS configuration. Like many projects, you can just leave both build systems.

  • You are using Qt4 for the UI example when the code is written in Qt5.

mohabouje avatar Jul 24 '19 14:07 mohabouje

Cmake generates it's own Visual Studio Solution files, it's why I didn't remove .pro files for QT creator. I think we can tweak the cmake script to find either QT4 or QT5 but I don't think it's necessary because any user can change that easily buy putting his own version. If you are using Visual Studio Code, which is very popular nowadays, you can easily build and debug the project without having a working Visual Studio installation. While I couldn't build the previous code with QT4 due to QCombobox differences it would only make sense to work with a fix that can work on either system. My fix there may not be perfect but the two examples in the project did compile and run just fine.

kenkit avatar Jul 24 '19 14:07 kenkit

To generate project files for any version of Visual Studio all you need is command prompt or Visual Studio Code Cmake extension. You can use this command for either migw or visual studion

mkdir build
cd build
cmake ../ -G "Visual Studio xxx"  -DQT_QMAKE_EXECUTABLE=path_to_qmake.exe -DCMAKE_BUILD_TYPE=Debug

The above command assumes you don't have qt bin dir in your path. You can also use the above command to generate Mingw make files To add your project to an existing project you only need to use cmake add_subdirectory Edit:I have not tested the project on migw or any other compilers

kenkit avatar Jul 24 '19 14:07 kenkit

I don't have QT5, so I couldn't test. If anyone can test and check if it builds I will appreciate the feedback

kenkit avatar Jul 24 '19 15:07 kenkit

Oh cool! I did not know that was that easy to generate a VS configuration. You'll never go to bed without learning something new :)

And regarding the .pro file, its mostly there for people who use qt-creator. Recent versions of qt-creator are well integrated with cmake, so eventually that file wont be useful at all.

The changes to make it work on Qt4 broke the example. The way the QComboBox is built is the following:

ui->audioMode->addItem("Default", WinToastTemplate::AudioOption::Default);

We add a human readable label and then the enum value in WinToast. When you do this:

static_cast<WinToastTemplate::AudioOption>(ui->audioMode->currentData().toInt())

You will get the value of the enum itself, while when you do:

static_cast<WinToastTemplate::AudioOption>(ui->audioMode->currentText().toInt())

You will get an integer equivalent to the conversion of "Default", or most probably an error or exception.

If you are looking for a fix that works in both version then try:

const auto index = ui->audioMode->currentIndex();
const auto data = ui->audioMode->itemData(index);
static_cast<WinToastTemplate::AudioOption>(data.toInt())

But personally, I would not bother myself to much with that. It's just an example of how to use it with Qt. Qt5 is the default version in most of the open-source I saw. In any case, Qt4 and Qt5 are not backward compatible. Once your project grows you will break one version. That's why users peak one version. Regarding the available features and all the updates, Qt5 tends to be the first option.

mohabouje avatar Jul 24 '19 15:07 mohabouje

I have not yet tested with QT5 I hope someone will be able to test and give some feedback. But it is possible to build even without any version of QT

kenkit avatar Jul 24 '19 17:07 kenkit

Thanks for the tip on the QComboBox , Let me try fixing it.

kenkit avatar Jul 24 '19 18:07 kenkit

Also I think there were some very useful compiler flags added into the Visual Studio Project files. We may have to add them in the cmake file

kenkit avatar Jul 24 '19 18:07 kenkit

I've just Tested Audio and it Works! I wondered why it didn't work last time but I assumed it's because of missing audio file or something

kenkit avatar Jul 24 '19 18:07 kenkit

Good point. I can take care of the part related to Qt5, that's not a critical one. Probably we should add the missing flags from the VS configuration. Actually, I like much more this new version with cmake, it just makes things simpler.

mohabouje avatar Jul 24 '19 19:07 mohabouje

Also it would be nice to add a cl service like appveyor so we can know when build's fail. I'm not sure if it's possible to implement tests, if it is I can also add google test framework within cmake. Like I did here https://ci.appveyor.com/project/getnamo/7zip-cpp/build/tests I think the tests that don't require user interaction will work fine.

kenkit avatar Jul 24 '19 21:07 kenkit

I already have that in other projects using CircleCI, the thing is that is hard to test this thing properly without mocking much stuff. Probably, I should give it a try.

mohabouje avatar Jul 24 '19 21:07 mohabouje

Ok, give it your best. it can be as easy as testing if the lbrary is loading, or testing if timers are consistent. But it's not important. For as long as you get "Build passing" in PR's or also you can go as far as adding codacy http://codacy.com/ or ~~LGTM https://lgtm.com/dashboard~~ so we can get code quality checks (LGTM) was a bit tough to setup a while back but I think it may have been fixed.. Some bugs are much easier to spot this way. EDIT:LGTM Might won't work since it's a linux environment.

kenkit avatar Jul 24 '19 22:07 kenkit

I will also look into linux maybe we can make a crossplatform notification system since we now have cmake.

kenkit avatar Jul 24 '19 22:07 kenkit

It doesn't look hard to implement https://askubuntu.com/questions/730050/how-to-use-notify-send-with-c

kenkit avatar Jul 24 '19 22:07 kenkit

I have not yet used automated tests in C / C++ applications, but how about automated end to end tests instead of or additional to unit tests?

ChristianGalla avatar Jul 25 '19 05:07 ChristianGalla

You can add whichever you think is best. I will update the script to enable tests on appveyor. The good thing is it will prevent broken builds from being merged before they are fixed.

kenkit avatar Jul 25 '19 07:07 kenkit

Hi all, FYI I have rewritten the whole CMakeLists.txt into a modern version, with Qt6 (which is released for a while), anyone who wishes to adopt it would be welcomed.

https://github.com/moodyhunter/WinToast/commit/cf03283a030d0d043120f4cfed813828cb907899

moodyhunter avatar Nov 06 '21 11:11 moodyhunter

The latest version is using CMake + QT6 CMake wrappers

mohabouje avatar Apr 10 '23 10:04 mohabouje