I want to develop a very simple licensing system. I decided to use Crypto++ v5.6.2 for generating public and private keys, cypher and decipher files. This library is build under Windows with Visual Studio and its solution files, but my project is using CMake for generating these solution files. Therefore, either I can write some CMake files for compiling Crypto++ or I can compile it and move the resulting files to my environment, using CMake to collect and include them in my solution. The latter is the approach that I have chosen with some libraries, since it is usually really difficult to write CMake files for building a library that you have not develop.
These are the steps I followed:
- Read Readme.txt at the root folder inside the zip file, and pay attention to the MSVC section. The cryplib project is the full static library project.
- I am using Ogre and other projects that force me to use shared C++ run-time libraries. Criptop++ use static C++ run-time libraries by default. As I explained in other posts, make sure that this setting is consistent across all your dependencies. Therefore, go to the cryplib Project Properties -> C/C++ -> Code Generation and switch from Multi-threaded to Multi-threaded DLL, in debug /MTd to /MDd and in release /MT to /MD.
- Ogre also uses multi-byte character set, so switch for all configurations General -> Character Set to Use Multi-Byte Character Set.
- Make sure Code Generation -> Enable Enhanced Instruction Set is set to /arch:SSE2 in release and debug.
- Following the same philosophy than Ogre and other libraries, I will build release and debug libraries with different names, in order to make it easier to add them by hand in my CMake project files. Switch to the debug configuration and find Target Name property at General, change its value to $(ProjectName)_d. It is advisable to rename the *.pdb files with the same name than the target name, so go to C/C++ -> Output files and and change its value to $(OutDir)$(TargetName).pdb.
- I will create another configuration for compiling in release mode with debugging information. Click on the Configuration Manager button. Unfold the Active Solution Configuration list, and select <New>. Then, choose in Copy settings from the release configuration, and use the CMake name for this kind of build RelWithDebInfo. Once the new configuration has been created, I recommend to save, close the IDE, and open it again. Now, make sure the release configuration does not include debugging information. C/C++ -> Debug Information Format should be empty, and this property in RelWithDebInfo configuration should be set to Program Database /Zi. Lastly, disable any optimization by setting C/C++ -> Optimization -> Optimization to Disabled (/Od).
- I do not want the whole program optimization, because other libraries do not use it, and some warnings or errors may happen when the final linking of my application is done. Hence, go to General -> Whole Program Optimization and set No Whole Program Optimization in release and RelWithDebInfo configurations. Besides, in Librarian -> Link Time Code Generation set it to No. Deactivation of /LTGC optimization flag must be done in both places, when compiling and when linking.
Finally, you are ready to compile and include the final results in your project. I created a new folder called Cryptopp with two folders: lib for the binaries and include for the header files. In my CMake files, ExternalDependencies.cmake contains the path to the include and binary folders, and the name of the libraries for the debug and release configurations, such as: