Overview
IDE is not required to build Fossil. However, IDE may be useful in development of the Fossil code. Staple IDE features that come to mind are ease of editing, static code analysis, source indexing, autocomplete, and integrated debugging.
Who may benefit from using an IDE? In general sense, of course, anyone who is used to a particular IDE. Specifically to Fossil development this could be:
Developers who are new to Fossil code; IDE helps navigate definitions and implementations across the source files
Developers who may be familiar with the code, yet would want to diagnose an issue that calls for in-depth debugging; IDE makes debugging somewhat more accessible
Current Fossil build process is Makefile-based, which extensively uses code-generation. It's flexible, yet as such it's not natively fitting any specific IDE. This often represents a challenge for an IDE workflow as it's trying to figure out the correct dependencies.
To assist with Fossil IDE workflow, there're currently two alternatives to consider depending on IDE capabilities to support it:
Use CMake-based workflow; in this case the Fossil's CMakeLists.txt file is directly used as the IDE project file
Import the existing Makefile and then tweak the resulting project settings to properly reference the dependencies
The following sections describe both approaches as tested with a selection of IDEs (not exhaustive).
USAGE NOTES: To get most utility out of IDE in Fossil development, it's recommended to do a general development in Release build configuration. In this case, compile errors would refer to original source files instead of the generated ones which actually get compiled. Clicking on such error message in the IDE output pane will bring up the source file and the offending line.
This somewhat reduces chances of making edits in the generated files just to see the precious code lost as the files get re-generated during build.
Switch to Debug build configuration once in a need to chase that bug that is playing hard to get. The debugger is stepping through the actually compiled code, that is the editor will load the generated files from the build directory. While fixing the bugs, just be aware of where to make the edits.
A simple rule of thumb is to keep only
<module>.csource files open, closing the files<module>_.c(underscored) and<module>.h(header) which get generated in the build directory.WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
CMake-based Fossil Workflow
Most major C/C++ IDEs handle CMake projects either natively or via native project files generated from the given CMakeLists.txt.
So far the Fossil CMake-based workflow has been tried with the following IDEs:
- Qt Creator (Linux, Windows)
- VisualStudio 2017 (Windows)
- Eclipse CDT (Linux)
- VSCode (Linux, Windows)
- Code::Blocks (Linux)
Using CMake on the Command-line
In general, the CMake workflow is very much the same on all of the supported platforms. CMake generator takes care of the platform/compiler specifics.
CMake can be used directly on the command-line to build the Fossil project in either Release or Debug configuration:
cd fossil
mkdir build-debug
cd build-debug
cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug
make
OR on Windows with MSVC:
cmake .. -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug
nmake
An IDE executes similar commands behind the scenes to generate and build a CMake-based project. In general, CMake is capable of generating native project files for a wide selection of IDEs. However for the Fossil CMake project, it's preferable to generate a Makefiles build system, because that's what the underlying Fossil build process is.
Below are the steps used to setup Fossil CMake project in the IDEs tested.
NOTE: To refresh a Project Tree View so that it shows the generated files, the easiest way is to re-save the
CMakeLists.txtfile. This triggers the IDE tools to regenerate the build system and rescan the project source files.
CMake workflow in Qt Creator has been supported for quite some time, so it evolved to become more streamlined. Below are the steps to set up CMake project in Qt Creator version 4.5 and above.
- From Weclome panel Open Project, browse to the Fossil project directory
and open the
CMakeLists.txtfile. - Qt Creator will prompt to select a Kit to configure the project.
For example,
Desktop Qt 5.9.4 GCC 64bit
At this point the project is already usable. Optionally, for convenience it makes sense to adjust some of the default settings.
- Open the Projects panel
- Remove the extra build configurations, keep Debug and Release
For each of the build configurations
- Select a Build directory. For example:
build-fossil-debug/directory orbuild-debug/subdirectory. - Set any additional CMake variables
- Select a Build directory. For example:
Now it's ready for build and use.
- Select the build configuration; for example
Debug - Do Build Project "fossil"; it runs the CMake and then starts the build showing the progress in the Compile Output pane
Refresh the Projects Explorer View so that it shows the generated files:
- Open the
CMakeLists.txtfile and trivially "touch" it then re-save it. - This triggers CMake which then re-populates the Project Explorer View adding the generated header files from the build directory.
- Open the
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()for the functionfossil_print()select context menu Follow Symbol Under Cursor -- the Fossil source filesrc/printf.cautomatically opens in editor.Set the run arguments -- panel Projects: Run; by default the
apptarget is already selected (bin/fossilexecutable):- Set the Command line arguments: for example,
version - Optionally, check Run in terminal
- Set the Command line arguments: for example,
Do Run OR
To start debugging -- do menu Debug> Step Into; the editor opens file
main_.c(generated!!), execution stops inmain(). Fossil executable output is shown in a separate terminal window.
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
Starting with Visual Studio 2017 CMake-based projects (CMakeLists.txt files)
are directly supported without the need to generate an intermediate MSBuild
project files. This feature is supported via Visual C++ Tools for CMake
component which is installed by default as part of the
Desktop development with C++ workload.
NOTE: By default, Visual Studio 2017 CMake Tools uses Ninja build tool. In general it has a better performance over the usual NMake, as it allows parallel build tasks. However in the scope of Fossil CMake project there's no real speedup, since the underlying Fossil Makefile is still built with NMake.
As Ninja tool has some subtle differences in handling of the
cleantarget, it's recommended to select the"NMake Makefiles"generator for the Fossil CMake project (which is a valid choice despite a possible warning.)
- Menu File> Open:Folder to open Fossil source project directory that
contains the
CMakeLists.txtfile Change the generator -- menu CMake> Change CMake Settings> fossil will open
CMakeSettings.jsonfile; in all of the defined configurations set:"generator": "NMake Makefiles", "buildCommandArgs": "",Save the settings file and the project is reconfigured automatically.
Select configuration -- toolbar Select Project Settings, for example:
x64-DebugDo menu CMake> Build All; build progress is shown in Output:Build pane
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()for the functionfossil_print()select context menu Peek Definition -- the Fossil source filesrc/printf.cautomatically opens the peek preview pane.Select a start target
bin/fossil.exe-- toolbar Select Startup ItemSet the run arguments -- menu CMake> Debug and Launch Settings in the file
.vs/launch.vs.json. For example, for "default" configuration append:"args": ["version"]Save the settings file.
To start debugging -- do menu Debug> Step Into; the editor opens file
main_.c(generated!!), execution stops inmain(). Fossil executable output is shown in a separate terminal window.
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
NOTE: If doing a cross-platform build, it's necessary to clean the builds of the external components that are used with Fossil (in
compat/subdirectory). For example,zlib,openssl. Failure to do that may manifest with the fireworks of compile and link errors.
To configure CMake-based project with Eclipse it first has to be generated as a native project, then imported into Eclipse as an existing project.
The CMake build directory should not be a subdirectory of the Fossil project source directory, but rather a sibling or other directory. For example:
workspace/
|-- fossil-debug/ <== CMake build directory
|-- fossil/ <== Fossil project directory
| `-- CMakeLists.txt
`-- fossil-release/
Generate Eclipse CDT4 makefiles, optionally specify the Eclipse's version:
cd workspace cd debug cmake ../fossil -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_ECLIPSE_VERSION=3.8 ls .cprojectFrom Eclipse do Import as a General>Existing Projects into Workspace from within the CMake build directory. This pulls both the Fossil CMake-based project and the original Makefiles-based project which appears under [Subprojects]/fossil
Do Build and then menu Project> C/C++ Index: Rebuild to pick up the generated sources needed for the code browsing and autocomplete
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()hover mouse over the call tofossil_print()-- this allows to peek at its implementation. Or select Open Declaration from the context menu.For running and debugging, create a new Run:Run Configuration for C/C++ Application; name it
fossil, pick a project executablebin/fossiland specify run arguments. For example:versionDo Debug fossil, which would switch to the Debug perspective and the editor opens file
main_.c(generated!!), execution stops inmain()
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
NOTE: Eclipse creates a few local files and folders to keep its settings, (namely
.project) which may already be part of Fossil, so make sure not to push them to the main Fossil repository.
If you're a regular VSCode user, you probably have all the needed C/C++ and CMake extensions already installed and set up. Otherwise, C/C++ and CMake extensions need to be installed from the marketplace to enable CMake support. For example:
- C/C++ ("C/C++", ms-vscode.cpptools)
- CMake Tools ("CMake Tools")
- CMake ("CMake For VisualStudio Code")
Then you may follow the CMake Tools "Getting Started" guide skipping to "Configuring Your Project" section. It's also helpful to review "C/C++" extension documentation for "Configuring launch.json for C/C++ debugging".
Briefly:
Open the Fossil source project folder in VSCode:
cd fossil code .CMake Tools extension notification prompts to configure your project
Select a Kit from the shown list. For example,
GCCCMake Tools then executes CMake commands and by default configures the project to build in
build/subdirectory with Debug configuration.In status bar set active target
app(it's set to[all]by default)Build the project -- status-bar command Build
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()for the functionfossil_print()select context menu Peek Definition -- the Fossil source filesrc/printf.cautomatically opens the peek preview pane.Set the run arguments -- menu Debug:Open Configurations for C/C++ in the file
.vscode/launch.json. For example, for "(gdb) Launch" configuration add:"program": "${workspaceFolder}/build/bin/fossil", "args": ["version"], "stopAtEntry": true, "cwd": "${workspaceFolder}/build",Save the file.
Switch to the Debug view and Start Debugging; the editor opens file
main_.c(generated!!), execution stops inmain()
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
- Create a build directory
Generate the Code::Blocks project from the Fossil
CMakeLists.txtfile:mkdir build-debug cd build-debug cmake .. -G"CodeBlocks - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug ls fossil.cbpOpen the generated Code::Blocks project
.cbpfileSelect and build
apptarget (Logs view shows Build log output)Re-run the CMake command to refresh the project tree so it shows the generated source/include files:
cmake ..Navigate source for definitions/implementations. For example, in
src/main.cfunctionversion_cmd()find the implementation offossil_print()-- the Fossil source filesrc/printf.cautomatically opens in editor to show the function body.Set the run arguments -- menu Project:Set program's arguments for target
app. For example:versionRun; OR
For debugging select Menu Debug:Step-in; the editor opens file
main_.c(generated!!), execution stops inmain()
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
Import the Existing Fossil Makefile
Many IDEs allow importing an existing Makefile based project. However, not all Makefiles are equally straightforward to import. Fossil's build process involves quite extensive use of code-generation, which complicates dependency resolution. The resulting IDE project file may turn up not very practical. Additionally, such an imported project will need to be maintained manually or re-imported to account for upstream updates in the Fossil project (additions, renames etc.)
On the plus side, once the resulting Fossil IDE project has been configured, it's as close to the original Makefile as it could be. Chances are the bulk of dependencies would remain fairly static, as the Fossil project evolution shows.
So far adopting of the Fossil Makefile project has been tried with the following IDEs:
- Eclipse CDT (Linux)
- Visual Studio 2017 (Windows)
The general approach for adopting the existing Fossil Makefile into an IDE is as follows:
Configure the Fossil project to generate the main Makefile (Linux and similar)
./configure --fossil-debugImport the existing Makefile project into via IDE's wizard or other facility
Try to build the resulting project (to check the dependencies)
Adjust the IDE project settings to resolve missing dependencies
Test the code indexing whether definitions/implementations are resolved into correct sources
Create and test the Debug configuration (defined FOSSIL_DEBUG preprocessor macro)
Below are the steps used to adopt Fossil Makefile project into the IDEs tested.
A configured Fossil Makefile-based project can be imported as is into Eclipse CDT. With a few tweaks, it allows code-browsing, autocomplete, and debugging.
Configure the Fossil project to generate the main Makefile (Linux and similar)
./configure --fossil-debugDo menu File> Import> C/C++: Existing Code as Makefile Project
Browse to the Fossil project directory
Pick the configured Toolchain, e.g.
Linux GCCOnce the import completed, the source tree is populated with source directories. At this point the project is already buildable, yet source browsing is not fully functional yet. Add the following settings:
Do Menu Project> Properties> C/C++ General: Paths and Symbols
Add Includes in workspace folders:
fossil/bld,fossil/srcAdd Output Location:
fossil/bldDo Build and then menu Project> C/C++ Index: Rebuild to pick up the generated sources needed for the code browsing and autocomplete
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()hover mouse over the call tofossil_print()-- this allows to peek at its implementation. Or select Open Declaration from the context menu.For running and debugging, create a new Run:Run Configuration for C/C++ Application; name it
fossil, pick a project executablebin/fossiland specify run arguments. For example:versionDo Debug fossil, which would switch to the Debug perspective and the editor opens file
main_.c(generated!!), execution stops inmain()
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.
NOTE: Eclipse creates a few local files and folders to keep its settings, (namely
.project) which may already be part of Fossil, so make sure not to push them to the main Fossil repository.
There're several ways of how to layout an imported project, here we show a straightforward way that makes use of Visual Studio's import wizard.
NOTE: In such a layout, the build directory
msvcbldis shared between the build configurations. This requires a clean re-build when switching the build configuration or target platform in case of cross-compiling.
Menu File> New> Project From Existing Code; a wizard starts
Project Type: Visual C++ Project file location: <Fossil project source directory> Project name: fossil Folders: src/ (Add subfolders: Yes) win/ (Add subfolders: Yes) Project Settings: Use external build system Build command line (Debug): win\buildmsvc.bat FOSSIL_DEBUG=1 Rebuild All command line (Debug): Clean command line (Debug): win\buildmsvc.bat FOSSIL_DEBUG=1 clean clean-zlib Output (Debug): msvcbld\fossil.exe Preprocessor definitions (Debug): Include Search Path (Debug): msvcbld;src;.;compat/zlib Build command line (Debug): win\buildmsvc.bat Rebuild All command line (Debug): Clean command line (Debug): win\buildmsvc.bat clean clean-zlib Output (Debug): msvcbld\fossil.exe Preprocessor definitions (Debug): Include Search Path (Debug): msvcbld;src;.;compat/zlibApply the settings.
New solution file
fossil.slnand project filefossil.vcxprojare created in the Fossil project source directoryChange the project build directory to
msvcbldfor All Configurations and All Platforms -- menu _Project> fossil Properties> General__Output Directory: $(SolutionDir)mscvcbld\ Intermediate Directory: mscvcbld\ Build Log File: $(IntDir)$(MSBuildProjectName)-$(Configuration).logSelect a target build configuration -- toolbar Solution Configurations, and Solution Platforms (For example,
Debug,x64)Do menu Build> Build Solution
Navigate definitions/implementations. For example, in
src/main.cfunctionversion_cmd()for the functionfossil_print()select context menu Peek Definition -- the Fossil source filesrc/printf.cautomatically opens the peek preview pane.Set the run arguments -- menu Project> fossil Properties: Debugging: Command arguments. For example:
versionTo start debugging -- do menu Debug> Step Into; the editor opens file
main_.c(generated!!), execution stops inmain().Before switching to another build configuration, do menu Build> Clean Solution; then switch and build.
WARNING: Edits to generated files in the build directory will NOT survive a Rebuild, and the changes cannot be committed directly to the project repository.
Make sure you edit files in the Fossil source directories.