Make management of decl export/import easier on Windows
As a | CEP developer] |
I would like to | have a hassle free development time on windows |
So that | I can spend more time prototyping |
About you
This is a merge between
- a feature request submitted on the old bugzilla by Céline on 2016-01-18, and titled "The wizard should create a API.h file when an action depends on a local CEP component"
- a story suggested on the old icescrum by myself on 2013-01-15, and titled "simplification of declspec export etc..."
- a story suggested on the old icescrum by Céline on 2014-06-04, and titled "Inclure les decl_export dans le Wizard"
Product
cepgenerator and wizard
Overview
On windows you need to declare that you "export" the symbols when you are compiling a library and "import" the symbol when you are linking to the library. That means that you have to modify your code for these two phases. This is generally done by using a macro (defined as export and import when MSVC is used or as nothing for other compiler).
This feature requests ask for automatic management of this not obvious behaviour.
This can be done by:
- use a specific macro that (with the combination of
Q_DECL_EXPORT
/Q_DECL_IMPORT
or the basic__declspec(dllexport)
/__declspec(dllimport)
- automatically include all symbols thanks to CMake WINDOWS_EXPORT_ALL_SYMBOLS property
- smoothly integrated this in the wizard/cepgenerator (see below)
cepgenerator/wizard integration
The wizard should create a API.h file when an action depends on a local CEP component
Create a new CEP with the wizard, containing a new Component (e.g. Albert's Component). Then create an action extension (e.g. Albert's Action) which depends on Albert's Component. The wizard adds a
NEEDS_COMPONENT_EXTENSION albertscomponents
in the action extensionCMakeLists.txt
, which is really great as the user do not have to look at the CMakeLists.txt anymore.However, if the user is on Windows (which do not really know how to make real dynamic libraries), he/she will need a file name AlbertsComponentAPI.h in his/her Albert's Component extension, a
DEFINES COMPILE_ALBERTSCOMPONENTS_API
in Component's extension CMakeList and aclass ALBERTSCOMPONENTAPI AlbertsComponent
declaration in its .h file...-- Céline
References
- https://doc.qt.io/qt-5/qtglobal.html#Q_DECL_EXPORT
- https://doc.qt.io/qt-5/sharedlibrary.html
- https://blog.kitware.com/create-dlls-on-windows-without-declspec-using-new-cmake-export-all-feature/
- old doc: https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/BuildingWinDLL
- old doc: https://cmake.org/cmake/help/v2.8.10/cmake.html#module:GenerateExportHeader