Created
December 6, 2015 05:41
-
-
Save nonkr/4dfa73a6ed9810c184f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off&cls | |
for %%* in (.) do set PROJECT=%%~nx* | |
set DISTFILE=cmakelist.tmp.txt | |
if exist %DISTFILE% del %DISTFILE% | |
echo cmake_minimum_required(VERSION 3.3.2)>>%DISTFILE% | |
echo project(%PROJECT%)>>%DISTFILE% | |
echo set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")>>%DISTFILE% | |
echo.>>%DISTFILE% | |
echo set(SOURCE_FILES>>%DISTFILE% | |
echo Searching *.c,*.h under %PROJECT%... | |
setlocal DisableDelayedExpansion | |
set "r=%__CD__%" | |
for /r . %%F in (*.c,*.h) do ( | |
set "p=%%F" | |
setlocal EnableDelayedExpansion | |
set "a=!p:%r%=!" | |
set excluded=false | |
rem 增加需要排除的源文件或目录进来 | |
for %%s in (main.c,.svn,.idea,deps) do ( | |
echo !a! | findstr "^%%s">NUL && set excluded=true | |
) | |
if "!excluded!"=="false" ( | |
call set a=%%a:\=/%% | |
echo !a! [source] | |
echo !a!>>%DISTFILE% | |
) | |
endlocal | |
) | |
setlocal EnableDelayedExpansion | |
echo )>>%DISTFILE% | |
echo.>>%DISTFILE% | |
rem 增加需要include进来的目录 | |
for %%s in (src) do ( | |
set "b=%%s)" | |
echo include_directories(!b!) >>%DISTFILE% | |
) | |
echo.>>%DISTFILE% | |
echo add_executable(%PROJECT% ${SOURCE_FILES})>>%DISTFILE% | |
set MAINFILE=main.c | |
if not exist %MAINFILE% ( | |
set "mainfunc=int main() { return 0; }" | |
echo !mainfunc!>>%MAINFILE% | |
) | |
if exist CMakeLists.txt del CMakeLists.txt | |
ren %DISTFILE% CMakeLists.txt | |
echo. | |
echo Generate CMakeLists.txt done. | |
pause |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment