Build improvements

Contains some fixes to the CMake files. CMake should now correctly detect all prerequisites and build the tests automatically. (Tested for Linux only.) You may also consider merging the branch to master.

Fix failing tests "free_function" and "test_object".