Skip to content

Basics of a csn file

ivmartel edited this page Nov 20, 2012 · 4 revisions

Here are a few examples of CSnake configuration files. These files are used by CSnake to define modules such as libraries, third parties and command line applications. It tell it where are the source files of the module, what are its dependencies and extra compilation flags for example. The inline comments should be enough to roughly understand the purpose of each line. For more details, please refer to the code documentation bundled with the CSnake release packages. To ease the creation of these csn files, we created a python helper tool called StartNewModule. The test folder of CSnake is also a good place to find examples.

Third Party

Here is an example configuration of the famous ITK.

# CSnake configuration of ITK

# CSnake imports
from csnAPIPublic import GetAPI
api = GetAPI("2.5.0")
# Other dependencies
from csnToolkitOpen import *

# Definition of the ITK third party
itk = api.CreateThirdPartyProject("ITK")
# Dependencies
itk.AddProjects([vtk])
# Where to find the CMake Use and Config files
itk.SetUseFilePath("%s/ITK-3.20/UseITK-3.20.cmake" % itk.GetBuildFolder())
itk.SetConfigFilePath("%s/ITK-3.20/ITK-3.20Config.cmake" % itk.GetBuildFolder())
# Files to install in the build folder
if api.GetCompiler().TargetIsWindows():
  itk.AddFilesToInstall(["bin/Debug/ITKCommon.dll"], debugOnly = 1)
  itk.AddFilesToInstall(["bin/Release/ITKCommon.dll"], releaseOnly = 1)

Library

Here is an example configuration of your new library 'MyLib'.

# CSnake configuration of MyLib

# CSnake imports
from csnAPIPublic import GetAPI
api = GetAPI("2.5.0")
# Other dependencies
from csnToolkitOpen import *

# Definition of the MyLib library
# (to create dynamic a library, use 'dll' instead of 'library')
myLib= api.CreateStandardModuleProject("MyLib", "library")
# Location of the source files
myLib.AddLibraryModules(["MySourceFolder0", "MySourceFolder1"])
# Dependencies
myLib.AddProjects([itk, vtk])
# Location of associated command line applications
myLib.AddApplications(["MyAppFolder0", "MyAppFolder1"]
# Location of the tests
myLib.AddTests(["tests/*.*"], cxxTest)

Definition file

As you may have seen, we use a specific import to a csnToolkitOpen.py file. This file is an instance definition file that allows to then refer to an instance when adding module dependencies. Placed at the root of your project, it loads its csn files to make them available to others. Here is its structure:

# CSnake definition file

# CSnake imports
from csnAPIPublic import GetAPI
api = GetAPI("2.5.0")

# Definition of the ITK third party instance
# Uses the API to load the third party from a 'thirdParty' folder (defined in the GUI)
# Here 'thirdParty/ITK-3.20/csnITK.py'
def itk():
  return api.LoadThirdPartyModule('ITK-3.20', 'csnITK').itk

# Definition of the MyLib library instance
# Load the library from a 'src' folder  (defined in the GUI)
# Here 'src/cilabModules/MyLib/csnMyLib.py'
def myLib():
  import cilabModules.MyLib.csnMyLib
  return cilabModules.MyLib.csnMyLib.myLib

Back to the User Guide.

Clone this wiki locally