Features :: Syntax




We believe that a clean, approachable, readable syntax is critical to the maintenance of a good build system. We believe the learning curve should be shallow, and anyone who's looking at a CSBuild makefile should be able to get a reasonable understanding of what's being done even if they have never used CSBuild before. To that end, we've designed CSBuild as an extension to python - everything in CSBuild is written in plain, straight-forward python, and anything valid to do in python is valid to do in CSBuild.

A makefile to build a library and an application which depends on that library (with an abundance of comments) might thus look like this:

 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
import csbuild

#Using the C++11 standard, gcc and clang require this to be set explicitly
csbuild.Toolchain("gcc", "android", "iOS").SetCppStandard("c++11")

#Build gcc-based toolchains with the clang compiler
csbuild.Toolchain("gcc", "android", "iOS").SetCCompiler("clang")
csbuild.Toolchain("gcc", "android", "iOS").SetCppCompiler("clang++")

#Target visual studio 2013
csbuild.Toolchain("msvc").SetMsvcVersion(120)

#Add a library location for our third-party libs
csbuild.AddLibraryDirectories("../3rdParty/lib")

#Simple library project
@csbuild.project(name="libMyLib", workingDirectory="libMyLib/src")
def libMyLib():
    #Build shared on linux and static on windows, we don't want to use dllexport!
    csbuild.Toolchain("msvc").SetOutput("libMyLib", csbuild.ProjectType.StaticLibrary)
    csbuild.Toolchain("gcc", "android", "iOS").SetOutput("libMyLib", csbuild.ProjectType.SharedLibrary)

    #equivalent to CMake PUBLIC declaration
    #This will affect this project and anything that depends on it
    @csbuild.scope(csbuild.ScopeDef.All)
    def AllScope():
        csbuild.AddIncludeDirectoriess(
            "libMyLib/include", 
            "../3rdParty/include/SomeLib", 
            "../3rdParty/include/OtherLib"
        )
		
    #equivalent to CMake INTERFACE declaration
    #These settings will only apply to the final executable built with this library 
    #listed as a (direct or indirect) dependency
    @csbuild.scope(csbuild.ScopeDef.Final)
    def FinalScope():
        #Make sure anything that links us also links our third party dependencies
        csbuild.AddLibraries("SomeLib" "OtherLib")

#Simple executable project that depends on libMyLib
@csbuild.project(name="myApp", workingDirectory="myApp/src", depends=["libMyLib"])
def myApp():
    csbuild.SetOutput("myApp", csbuild.ProjectType.Application)

    csbuild.AddIncludeDirectories(
        "../3rdParty/include/AdditionalLib", 
        "../3rdParty/include/YetAnotherLib"
    )

    #Link additional third-party dependencies.
    #libMyLib and the libraries it depends on are linked automatically because it's 
    #listed as a dependency
    csbuild.AddLibraries(
        "AdditionalLib",
        "YetAnotherLib"
    )

In addition to attempting to provide a clean and readable syntax, CSBuild also believes in giving the developer control of their project layout. Thus, you can lay out your makefiles however you want - all in one makefile or split into several - and you can place them wherever you want, whether that be in a dedicated build directory or nested into the projects. CSBuild leaves that decision to you.

<< Features: Speed Features: GUI >>
CSBuild is a product of 3Jade Technologies, © 2013-2014 Jaedyn K Draper
Major contributions from Brandon M Bare/Aegresco LLC