Simplify cmake by creating macro and add dependency to math library.