cmake: Clean up code which processes optional dependencies

After making Boost optional some changes were needed to make cmake
generate a proper build system without Boost installed. This commit
modifies cmake files to properly handle optional dependencies.

Change-Id: I500d54233886552946eca68d173d14897ec0d8c3