This ticket is to simplify CMakeList.txt and replace some blocks of code with cmake macros. A new file with macros will be added.