Is it possible for amper to support c/c++ by gener...
# amper
s
Is it possible for amper to support c/c++ by generating compilation_database.json?
a
Hi! It is not possible. What project type do you work with? Do you have multiple languages maybe? Do you use Gradle? Thanks.
s
@andrey.dernov Sorry for the late reply, I went actually use some c/c++ development and make them use with Kotlin, I have some ideas now. Amper's yaml is really easy to use to configure a project, and I'd like to use it with c/c++. Some ideas: Project Configuration Library Naming: Every C/C++ library must have a unique name.
type
type can be: •
c/lib
c/app
cpp/lib
cpp/app
This is similar to
jvm/app
or
jvm/lib
, where a
cpp
type product may include C source files.
platforms
In C/C++ projects, platforms are often represented as macro preprocessors (e.g.,
#ifdef WINDOWS_64
). We can pass the platform as a macro to the compiler and generate
compilation_database.json
. Alternatively, and preferably, we can pass different source sets to the compiler instead of using macros directly(but should still be provided).
variants
Although not currently implemented in Amper, variants are a valuable feature. For C/C++, different build configurations (e.g., debug, release) can be implemented using variants, allowing different source sets to be passed to the compiler.
dependencies
Include Another Amper C/C++ Module: Include the path when passing to the compiler and use
#include <lib_name>
in the code. • Include a Module from Repository: While C/C++ lacks a standard repository, the concept remains the same: include the path for the compiler and use
#include <libname>
.
settings
C/C++ projects can have specific settings categories, such as compiler settings. Common options such as custom includes, optimization levels, and libc options. Amper can provide commonly used compiler options for these settings. Toolchain Integration CMake is widely used. However Amper's configuration file can be easily evaluated, adding special support for Amper should be straightforward. Alternatively, generating
compilation_database.json
is another viable option. Source Files Layout • Common Layout:
include
src
Platform-Specific Layout:
include@platform
src@platform
This approach, similar to Amper, is preferred over macros (though macros should also be supported). Build Output Common C/C++ library output includes headers and static or dynamic libraries for different platforms. We should preprocess include header files from different
include@platform
directories into a single file, ensuring other tools can use the output library properly. For applications, the process is straightforward.