Creating a new Project using crea
Run creaNewProject from the Start menu or the installation directory of CreaTools-2.0.2/bin
- A dialog to select a directory appears; select the directory where you want to create the project (ex. c:/Creatis)
- Type the project name (ex. : creaExample).
- You should get a file structure like the following
Creatis/creaExample
CMakeLists.txt
appli
CMakeLists.txt
template_appli
CMakeLists.txt
lib
CMakeLists.txt
template_lib
CMakeLists.txt creaSystem.h creaSystem.h.in
- Edit the root CMakeLists.txt (ex. C:/Creatis/creaExample/CMakeLists.txt) if you need to use any of the libraries listed below, set the option according to "ON" (ex. creaExample uses VTK and wxWidgets), setting to ON these variables, will allow crea to find and use the libraries.
SET(USE_CREA OFF) SET(USE_GDCM OFF) SET(USE_GDCM_VTK OFF) SET(USE_GDCM2 OFF) SET(USE_WXWIDGETS ON) SET(USE_KWWIDGETS OFF) SET(USE_VTK ON) SET(USE_ITK OFF) SET(USE_BOOST OFF) SET(USE_DOXYGEN OFF) SET(USE_LATEX OFF) SET(USE_TTH OFF)
- Note: Notice the SUBDIRS() command at the end of the file, this command will recurse into the subdirectories.
- 1.1 To compile packages you need to set USE_BOOST to ON
1.2 To compile packages you need to include the directory of the package in CMakefiles.txt
SUBDIRS( <PACKAGE> ) ,
at the end of the file.
Creating a new library
To add a new library go to the lib directory of your project (ex. : /Creatis/creaExample/lib)
- Create a directory and name it according to the library you want to create (ex. : exampleLib)
- You must edit the CMakeLists.txt by adding a SUBDIRS() command (ex. : edit /Creatis/creaExample/lib/CMakeLists.txt)
- Add at the end of the file SUBDIRS("name of the directory you created") (ex. : SUBDIRS(exampleLib))
- Copy the CmakeLists.txt file from "/lib/template_lib/CmakeLists.txt" into the directory of the library you want to create (ex. copy /Creatis/creaExample/lib/template_lib/CmakeLists.txt into /Creatis/creaExample/lib/exampleLib)
- Edit the copied CMakeLists.txt by changing the library name, at the top, change "SET(LIBRARY_NAME MyLib) to SET(LIBRARY_NAME "your lib name") (ex. : SET(LIBRARY_NAME MyLib) to SET(LIBRARY_NAME exampleLib)
- If this library must link against other libraries add them or uncomment the lines in the SET ( ${LIBRARY_NAME}_LINK_LIBRARIES option, e.g. : remove # before ${VTK_LIBRARIES}, if you need to link against VTK
- Now you can start adding your source files into this directory, when the project is generated for VisualStudio, this files will appear under your library (ex. : create the files main.cxx and main.h under /Creatis/creaExample/lib/exampleLib/)
- Note: The default is to create a DynamicLibrary, if you need to create a static library,
- Put <MyLib>_BUILD_SHARED OFF in CMake,
- or
- comment the line
- CREA_ADD_LIBRARY( ${LIBRARY_NAME} ) in line 58, and add the following lines
- ADD_LIBRARY(${LIBRARY_NAME} STATIC ${${LIBRARY_NAME}_SOURCES})
- TARGET_LINK_LIBRARIES(${LIBRARY_NAME} ${${LIBRARY_NAME}_LINK_LIBRARIES} )
- Add to the /lib/CmakeLists.txt file the directory of your new library.
subdirs(exampleLib)
Creating the executable for your application
- To add a new application go to the appli directory of your project (ex. /Creatis/creaExample/appli)
- Create a new directory according to the name of the application (ex. exampleAppli)
- You must edit the CMakeLists.txt by adding a SUBDIRS() command (ex. edit /Creatis/creaExample/lib/CMakeLists.txt)
- Add at the end of the file SUBDIRS("name of the directory you created") (ex. SUBDIRS(exampleAppli))
- Copy the CmakeLists.txt file from "/appli/template_appli/CmakeLists.txt" into the directory of the application you want to create (ex. copy /Creatis/creaExample/appli/template_appli/CmakeLists.txt into /Creatis/creaExample/appli/exampleAppli)
- Edit the copied CMakeLists.txt by changing the EXE_NAME in the top, change "SET(EXE_NAME MyExe) to SET(EXE_NAME "your exe name") (ex. change SET(EXE_NAME MyExe) to SET(EXE_NAME exampleAppli))
- If the exe file link against other libraries:
- add the path of the .h files in line INCLUDE_DIRECTORIES ex. ../../lib/<your_dir_library>
- add or uncomment the lines in the SET ( ${LIBRARY_NAME}_LINK_LIBRARIES option. ex(uncomment ${WXWIDGETS_LIBRARIES}, ${VTK_LIBRARIES} and add exampleLib (library created in step 2))
- Go to BBTK documentation
-> Online doc (guides, doxygen, core packages)and pdf guides -> Package Developer's Guide
- To include the MyLib (library of the project) in the your package, you have to modify the CMakefile.txt of your PACKAGE
#===============================================
SET(${BBTK_PACKAGE_NAME}_INCLUDE_DIRS
# LIST HERE YOUR ADDITIONAL INCLUDE DIRECTORIES
# EXCEPT :
# - src
# - bbtk dirs
# - automatically handled libraries or packages : wx, vtk... (see above)
# - the dirs automatically set by other libraries found by FIND_PACKAGE
../lib
)
#===============================================
#===============================================
SET(${BBTK_PACKAGE_NAME}_LIBS
# LIST HERE THE ADDITIONAL LIBS TO LINK AGAINST
# EXCEPT : the same libs than for INCLUDE_DIRS
MyLib
)
#================================================
- CMake configuration
- Generate your project in a different directory of your CMakefile.txt
Example:
Where is the soure code: C:CreatisTestep3
Where to build the binaries: C:CreatisTestep3Bin
- When you launch CMake, you have to verify de following configuration
Boost_INCLUDE_DIR C:/Program Files/boost/boost_1_37
BUILD_ALL ON
BUILD_BBTK_PACKAGE_<yourPackage> ON
BUILD_<yourPackate>_DOC_GUIDES_HTML OFF
BUILD_<yourPackate>_DOC_GUIDES_PDF OFF
<MyLib>_BUILD_SHARED OFF
- Generate your project in a different directory of your CMakefile.txt
- Run your sln project in your binary directory (C:CreatisTestep3Bin)
- Compile in RelWithDebInfo mode.
- Configure bbStudio to use your package