yipo
9/17/2015 - 5:04 PM

Create CMake projects for C++ on Windows, and version controlled by Git.

Create CMake projects for C++ on Windows, and version controlled by Git.

@ECHO OFF

PATH ^
%ProgramFiles%\Git\bin;^
%ProgramFiles(x86)%\Git\bin

IF "%~1" == "" EXIT /B 1

SET PROJECT_NAME=%~1
SET PROJECT_NAME=%PROJECT_NAME: =_%

ECHO Create project "%PROJECT_NAME%"

git init %PROJECT_NAME%

PUSHD %PROJECT_NAME%

> %PROJECT_NAME%.hpp (
    ECHO #pragma once
    ECHO.
    ECHO class %PROJECT_NAME%
    ECHO {
    ECHO };
    ECHO.
)

> %PROJECT_NAME%.cpp (
    ECHO #include "%PROJECT_NAME%.hpp"
    ECHO.
    ECHO int main^(^)
    ECHO {
    ECHO     return 0;
    ECHO }
    ECHO.
)

> CMakeLists.txt (
    ECHO.
    ECHO project^(%PROJECT_NAME%^)
    ECHO add_executable^(${PROJECT_NAME} %PROJECT_NAME%.hpp %PROJECT_NAME%.cpp^)
)

> CMake.bat (
    ECHO @ECHO OFF
    ECHO CD /D %%~dp0
    ECHO.
    ECHO PATH ^^
    ECHO %%ProgramFiles%%\CMake\bin;^^
    ECHO %%ProgramFiles^(x86^)%%\CMake\bin
    ECHO.
    ECHO IF NOT EXIST build MKDIR build
    ECHO CD build
    ECHO.
    ECHO cmake %%* ..
    ECHO PAUSE
)

> .gitignore (
    ECHO /build/
)

git add .

POPD

Create CMake Project (Batch Script)

for C++ on Windows, and version controlled by Git.