Next: 06 - Storage Module, Previous: 04 - Generator Module
eVaf uses CMake as its build system and needs a file called CMakeLists.txt in the src/apps/PswGen/Generator directory. Create the file and start editing it.
We use the TARGET variable to set the name of the module. This makes it easier to re-use the CMakeLists.txt file in other modules and applications.
set(TARGET PswGen)
Then we include Qt include files and libraries. We also specify, that we do not want to include the QtGui module as this module does not any classes from the QtGui module. By removing the QtGui module, we remove any graphical libraries as dependencies for this module and it can be used in headless systems.
set(QT_DONT_USE_QTGUI TRUE) include(${QT_USE_FILE})
Add all the eVaf include directories to the compiler. The variable eVaf_INCLUDE contains all the eVaf include directories and is already initialized with proper values when this CMakeLists.txt file is processed.
include_directories(${eVaf_INCLUDE})
Then we initialize a variable with the names of all the eVaf modules that this module needs to be linked with. We only need to specify the names of libraries without prefixes or suffixes like ".dll" or ".so". These libraries also become dependencies of this module and will be built whenever we build this module.
set(eVaf_LIBRARIES CommonLib PluginsLib)
Collect all the source files that needs to be compiled:
set(SRCS module.cpp )
Collect header files that need to be processed with the Qt meta-object compiler. Any header file that contains class declarations with the Q_OBJECT keyword and/or signals and slots, needs to be included here. To avoid warnings during the build, do not include here any other header files.
set(MOC_HDRS module.h )
The following line adds the Windows version info resource file to the list of source files:
if(WIN32) set(SRCS ${SRCS} version.rc) endif(WIN32)
Process specified header files with the Qt meta-object compiler:
qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS})
Put it all together and compile the module:
add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS})
Finally, link the module:
target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES})
And the final CMakeLists.txt file looks the following:
# src/apps/PswGen/Generator/CMakeLists.txt # Name of the target set(TARGET PswGen) # Qt modules set(QT_DONT_USE_QTGUI TRUE) include(${QT_USE_FILE}) # Include directories include_directories(${eVaf_INCLUDE}) # Required eVaf libraries set(eVaf_LIBRARIES CommonLib PluginsLib) # Source files set(SRCS module.cpp ) # Header files for the Qt meta-object compiler set(MOC_HDRS module.h ) # Version info resource file for Windows builds if(WIN32) set(SRCS ${SRCS} version.rc) endif(WIN32) # Run the Qt meta-object compiler qt4_wrap_cpp(MOC_SRCS ${MOC_HDRS}) # Compile the module add_library(${TARGET} SHARED ${SRCS} ${MOC_SRCS}) # Link the module target_link_libraries(${TARGET} ${QT_LIBRARIES} ${eVaf_LIBRARIES})
We also need CMakeLists.txt files in parent directory src/apps/PswGen. In this file we add the PswGen directory to the list of include directories, which makes it possible to use
# src/apps/PswGen/CMakeLists.txt set(eVaf_INCLUDE ${eVaf_INCLUDE} ${SMAKE_SOURCE_DIR}/src/apps/PswGen) add_subdirectory(Generator)
Modify the CMakeLists.txt file in the src/apps directory and include the PswGen application:
# src/apps/CMakeLists.txt # ... add_subdirectory(PswGen)
Now our module is included in the build system and we can try to compile it. Go to the eVaf root directory and create a build directory:
evaf $mkdir build
evaf $cd build
In the build directory, run cmake:
evaf/build $ cmake ..
If cmake finishes without errors, build the module with the make command:
evaf/build $ make PswGen
If you get compiler errors during the build, fix them. If the build finishes without errors, check the content of the bin directory:
evaf/build $ ls bin
libCommonLib.so* libPluginsLib.so* libPswGen.so*
evaf/build $
As you can see, there are three libraries now. The libPswGen.so is our module and others are eVaf libraries that our module needs in order to be run.
In the next section 06 - Storage Module we write the Storage module.