move search code out of main CMakeLists.txt