Building for Linux and Windows
-
I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Will this setup work and if not, which is the "right" way of achieving this?
-
I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Will this setup work and if not, which is the "right" way of achieving this?
@deisik said in Building for Linux and Windows:
Will this setup work and if not, which is the "right" way of achieving this?
Use a proper source code management system like git and share your repository via e.g. github.
-
@deisik said in Building for Linux and Windows:
Will this setup work and if not, which is the "right" way of achieving this?
Use a proper source code management system like git and share your repository via e.g. github.
@Christian-Ehrlicher companies will use a server for its products instead of github.
-
I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Will this setup work and if not, which is the "right" way of achieving this?
@deisik which qt version are you using now?
if you use qt5, either pro file or cmake will do the job for you. In pro file you can useunix { do settings for linux } win32 { do settings for Windows }
cmake file has similar settings.
if you use qt6, cmake is preferred. It depends on how big your project is. If it is small, one cmake or pro file is good enough. if your project is big, you can split the build file into a few files. For example, I build my project for Linux and Android with about 8-10 build files for easier changes.
since your build your project on two platforms, you sure need two dirs. But you use the same dir name.
-
@deisik which qt version are you using now?
if you use qt5, either pro file or cmake will do the job for you. In pro file you can useunix { do settings for linux } win32 { do settings for Windows }
cmake file has similar settings.
if you use qt6, cmake is preferred. It depends on how big your project is. If it is small, one cmake or pro file is good enough. if your project is big, you can split the build file into a few files. For example, I build my project for Linux and Android with about 8-10 build files for easier changes.
since your build your project on two platforms, you sure need two dirs. But you use the same dir name.
@JoeCFD Only a small part of my app needs special love (the Windows-only part that calls some external dlls), and I use stubs where the code should be separated between the platforms
It is too early to tell, but it looks like my setup is working. For a one-man army and as long as you don't try to edit the same file from Linux and Windows simultaneously, you should do fine
@JoeCFD said in Building for Linux and Windows:
since your build your project on two platforms, you sure need two dirs. But you use the same dir name.
I use the same source directory and two separate build directories for each platform (like project-build-Linux and project-build-Windows) in the same parent directory on the Linux machine as this is what shadow build requires as far as I can tell
-
I am porting my application to Windows and I want to use the same source code directory for building on both Linux and Windows so as not to end up having to support two different projects
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Will this setup work and if not, which is the "right" way of achieving this?
@deisik said in Building for Linux and Windows:
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)
To me, your approach is a valid solution to the problem.
-
@deisik said in Building for Linux and Windows:
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)
To me, your approach is a valid solution to the problem.
After testing my setup for nearly two months, I should say that it works in general, with the caveat being that the compile times on Windows are notably longer (apparently due to network as the project resides on the Linux machine and, consequently, its build directory is there too)
-
@deisik said in Building for Linux and Windows:
Will setting up two different build directories for each platform do the trick, with the same source code edited and compiled on Linux for Linux and on Windows for Windows?
Yes, this will do. You should make sure to just have a single project file both for Windows and Linux. Compiling to different directories is mostly sufficient. (Now, that I think about this: I believe that Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux. This might mess up a few things when you switch. Toggling between Debug and Release mode in Qt Creator should recreate the Makefile in this case. Better: Use CMake instead as its makefiles are stored in the build directory.)
To me, your approach is a valid solution to the problem.
@SimonSchroeder said in Building for Linux and Windows:
Qt Creator for qmake projects will write a Makefile to the main folder both on Windows and Linux
There is no difference between qmake and cmake here.
It will put the Makefile in you build directory, so if you have different build dirs for the Linux and Windows builds that just works.