summaryrefslogtreecommitdiffstats
path: root/arduino-cmake/configure.bat
blob: 580635db13f0f1441bab71cc79bb49d6f11e43bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
::===========================================================================::
:: Author: QueezyTheGreat                                                    ::
:: Description: Small wrapper around cmake and cmake-gui for                 ::
::              easy build system configuration and generation.              ::
::===========================================================================::
@echo off

set CURRENT_PATH=%CD%

set CONFIGURE_PATH=%~dp0%
set CONFIGURE_MODE=%1
set CONFIGURE_ARGS=%*

set BUILD_PATh=build

set CMAKE_NAME=cmake.exe
set CMAKEGUI_NAME=cmake-gui.exe


:: Parse arguments
if /i [%CONFIGURE_MODE%] EQU [-h]      goto :print_help
if /i [%CONFIGURE_MODE%] EQU [--help]  goto :print_help
if /i [%CONFIGURE_MODE%] EQU [/?]      goto :print_help


:: Check dependencies
for %%X in (%CMAKE_NAME% %CMAKEGUI_NAME%) do (
    set FOUND=%%~$PATH:X
    if not defined FOUND (
        echo %%X missing on the path, aborting!
        echo.
        echo Please ensure that CMake is available on the system path.
        echo.
        pause
        goto :EXIT
    )
)

:: Generate/Configure build
call :init_build
call :setup_build


::===========================================================================::
::                                                                           ::
::===========================================================================::
goto :EXIT


:: Initialize build path
:init_build
    if "%CURRENT_PATH%\" EQU "%CONFIGURE_PATH%" (
        :: In sources, create build directory
        set "BUILD_PATH=%CONFIGURE_PATH%%BUILD_PATH%"

        :: Create build directory
        if not exist "%BUILD_PATH%" (
            mkdir "%BUILD_PATH%"
        )
    ) else (
        :: Out of sources, do nothing
        set BUILD_PATH=%CD%
    )
    goto :RETURN

:: Configure/Generate build system
:setup_build
    cd "%BUILD_PATH%"
    if /i [%CONFIGURE_MODE%] EQU [-c] (
        :: Command Line version (cmake)
        echo cmake %CONFIGURE_ARGS:~3% "%CONFIGURE_PATH%"
        %CMAKE_NAME% %CONFIGURE_ARGS:~3% "%CONFIGURE_PATH%"
    ) else (
        :: GUI version (cmake-gui)
        start %CMAKEGUI_NAME% "%CONFIGURE_PATH%"
    )
    cd "%CURRENT_PATH%"
    goto :RETURN

:: Display help message
:print_help
    echo configure [-h ^| -c OPTS]
    echo     -h    Display this message
    echo     -c    Command line version of CMake
    echo.
    echo   OPTS    Options to pass to CMake command line
    echo.
    echo  Small wrapper around cmake and cmake-gui for
    echo  easy build system configuration and generation.
    echo.
    echo  For GUI and command line use.
    goto :EXIT

:RETURN
:EXIT