file (GLOB files src/*.cpp) foreach (file ${files}) string(REGEX REPLACE ".+/(.+)\\..*" "\\1" exe ${file}) add_executable (${exe} ${file}) message (\ \ \ \ --\ src/${exe}.cpp\ will\ be\ compiled\ to\ bin/${exe}) endforeach ()https://github.com/anonymouss/my-leetcode-cpp/blob/master/CMakeLists.txt