137 Mixing Xc++ and C++
As of Nov 2022 we either have Xc++ or C++ projects, we don't support a mixture within a single project. Given the downsides of using Xc++ related to dealing with compilation errors, it would be preferable to support both kinds of files in a single project. To allow this we shall use the extension xcpp and xh for source files written in Xc++. This is a good time to review the build system.
Currently a project file (.xcpj) uses xcpp to declare that the project is pure Xc++.
We shall add a new mode using mixed to declare the project to be using the mixed mode.
Eventually we can make this the default?
When an Xc++ file is translated the extension is changed (from .xcpp to .cpp and from .xh to .h).
We allow for a mixture of #include of C++ headers and @import of
Xc++ headers.
Ensuring the relevant files are recompiled when the project changes
The cmake documentation says it is a bad idea to use file GLOB to automatically
define the files to be compiled.
cmake_minimum_required(VERSION 3.3)
project(myproj)
add_definitions("-Wall" "-g")
include_directories(${PROJECT_SOURCE_DIR})
file(GLOB SRC_FILES ${PROJECT_SOURCE_DIR}/*.cpp)
add_executable(myproj ${SRC_FILES})
It is proposed that we take the following approach:
- Xc++ and C++ files uses different extensions so we can tell them apart
- We avoid the need for the file
project/src/project.xcpj - A file named
project/src/sourcefiles.txtdefines the set of source files in the project. This uses logical paths. This file is checked into the repository and is used to perform a build. - There is a script which can be run manually to update
project/src/sourcefiles.txtby looking at the files on the file system. The files are ordered lexicographically. This script can be run at the root level. - Xcpp uses
project/src/sourcefiles.txtto work out what files exist
Alternatively: We try to keep the xcpj format, but instead allow a script to be used to update it automatically.