Fix main cmake file to use a variable only after it was defined