I am using automake to build several projects in C++ and the projects will have quite some files in common. I have one git repository for each of the projects and one repository for the common files. Each project is going to be distributed as a separate package.
My file structure looks something like this:
project_1
src
include
project_2
src
include
common_files
src
include
How should I setup automake within each project and within the common_files to reflect this structure and make each of the projects possible to distribute?
Many thanks for suggestions.
/M
Related
Is it possible to configure a Bazel custom toolchain to include directories in the repository?
Assume that I have following in the root of my repository:
sysroots/armhf/include/myheader.h
sysroots/amd64/include/myheader.h
myproject1/component.cpp
myproject2/component.cpp
I'd like to configure toolchain such that when I run bazel build --config armhf, component.cpp files including myheader.h would get the header from sysroot/armhf/include directory, and when I run bazel build --config amd64, file from corresponding sysroot/amd64 directory were used.
This needs to work without having to modify projects containing component.cpp files.
Essentially I would like to check in platform specific headers and binaries in the source repository along with the code.
If you haven't found it yet, you need to write C++ toolchains. The Configure C++ Toolchains Tutorial is a good place to start, if you have more specific questions they'll get better answers as separate questions. I'm going to answer specifically about the paths here.
Most of the paths are just normal paths relative to the execution root. That typically means external/<repo_name>/<package>/<name> for paths in external repositories, or just <package>/<name> for paths in the main repository. bazel-toolchain's pkg_path_from_label function implements this logic, for example. In your case, that's sysroots/armhf/include for the first path.
cxx_builtin_include_directories is special. Paths there have unique syntaxes to generate absolute paths. The relevant one looks like "%package(#your_toolchain//relative/clang/include)%", with #your_toolchain replaced with your repository's name. In your case that means something like "%package(#//sysroots/armhf)%/include/myheader.h". Depending on where the package boundary is (deepest folder with a BUILD file) more or less of that might need to be in the %package() part.
Those directives get expanded when generating compiler command lines. I'm not aware of any documentation besides the source.
I'm trying to put together a CMake project where I have different packages that I need to build. This is my desired structure:
package1
src
file.cpp
test
file_test.cpp
package2
src
file2.cpp
test
file2_test.cpp
CMakeLists.txt
main.cpp // this will be removed later
This is my current CMakeLists.txt file:
cmake_minimum_required(VERSION 3.10)
# set the project name
project(cppApp)
# specify the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED True)
include_directories(${PROJECT_SOURCE_DIR})
# add the executable
add_executable(cppApp main.cpp ./package1/src/file.cpp ./package2/src/file2.cpp)
So the question is firstly, is a library considered a package in CMake? This question comes from someone who have done a lot of Java where I would typically call that a package and not a library. But does it in CMake?
Also, how do I in CMake include all files in the "packages" to be built instead of hard coding in the files as an executable? If I create many .cpp/.h files I want to automate this as much as possible.
I have seen that some other projects use a CMakeLists.txt file inside each "package", is this ideal? And is this good practice?
If you have a better suggestion according to some standard I should use to structure my project I would like to know a good one as well.
So the question is firstly, is a library considered a package in
CMake? This question comes from someone who have done a lot of Java
where I would typically call that a package and not a library. But
does it in CMake?
Your definition of package in Java is not quite accurate. Package is just a mean to organize classes in Java in namespace manner. It could be classes of a separate library, but nothing prevents you from using different packages within the same project. It has nothing to do with CMake packages, where each package is actually a whole separate project.
I have seen that some other projects use a CMakeLists.txt file inside
each "package", is this ideal? And is this good practice?
CMakeLists.txt files in subdirectories merely define new subset of rules for those directories. In order to make your CMake project respect those rules, you add such directory with add_subdirectory. It's not neccessarily a separate library, you can make subset of rules for parts of a single project, and it's usually a good idea to do that if some files are really that different.
CMake have something called add_library(lib) and is those kinds of directories considered a library?
add_library creates so-called CMake target, just like add_executable. The targets can be linked with each other with use of target_link_libraries, and that will indeed be considered a library in terms of C++.
I want to build two projects using cmake (A library and sandbox application using that library).
I'm currently having the following folder structure:
-- yanthra_engine
|
-- CMakeLists.txt
-- lib
-- ...
-- sandbox
|
-- CMakeLists.txt
-- out
-- ...
The yantra_engine builds a library where as sandbox builds an executable(using the above mentioned library).
Should I keep full fledged CMakeLists files for both the projects? Is there any efficient folder structure to follow?
I would like the library to build automatically when building my sandbox application, but not vice-versa.
You should keep seperate CMakeLists.txt files. It's good practice to use one CMakeLists.txt file per unrelated target. (Unrelated in the sense of not being different builds of the same library, e.g. one shared one static.)
Whether to add both targets to the same project is basically up to you. If the library is properly set up, you could create a seperate project for the library and use it's install target to install the library including cmake configuration files on your machine making it easy to import the installed library as a target to the sandbox project. This requires you to add the appropriate install commands to the library.
If you want to be able to build both the library and the sandbox via the same build files, basically all you need to do is to make sure both CMakeLists.txt files are reachable from a CMakeLists.txt file.
Without location of any of the files you could e.g.
Create a CMakeLists.txt file in the parent folder adding both subdirectories
cmake_minimum_required(VERSION 3.0)
project(CommonProject)
add_subdirectory(yanthra_engine)
add_subdirectory(sandbox EXCLUDE_FROM_ALL) # targets in sandbox not built by default.
You could also include the yanthra_engine directory from sandbox/CMakeLists.txt
...
add_subdirectory(../yanthra_engine "${CMAKE_BINARY_DIR}/yanthra_engine_build")
...
Both approaches allow you to either set up a build project for the lib on its own or set up a build project for both. In approach 1 the source directory for building both would be the parent directory of yanthra_engine and sandbox and in approach 2 it would be sandbox.
For both approaches you don't need to wory about unnecessarily building the sandbox project though as long as you specify the target you want to build. Since sandbox links the lib but there is no dependnecy established the other way round building sandbox makes sure the lib is up to date, but building the lib only builds the lib and its dependencies which excludes the sandbox.
One thing you can try is to let yanthra be a subdirectory of sandbox. Then you can do this in sandbox:
add_subdirectory(yanthra_engine)
I am currently wondering how I can solve the situation, that I want to work on a C++ project from multiple devices with different OSs. So my idea was to just push my .cpp and .h files up. So I tried to clone it and create a project with exisiting sources files. I was hoping Netbeans would realize where to put the files in the right project subdirectories (like header files/source files). However it doesn't work because it needs the Makefile. Which is pointless though to push the Makefile up to git, since it contains information about the previous OS.
Is there a way that Netbeans will be smart enough to figure just out to put the files in the right folders and then I can compile it from scratch without existing Makefiles from the previous operation system?
Thank you very much.
I'm doing what #user4581301 was talking about for many years.
IMPORTANT: The Netbeans project type must be "C/C++ Project with Existing Sources".
The Makefile contains an ifeq statement, so it works differently on Linux and Windows:
MAIN = tc0001
ifeq (${OS},Windows_NT)
include ${MAKELIBHOME}/MINGW32.inc
include ${MAKELIBHOME}/WINDOWS.inc
else
MAKELIBHOME := ${HOME}/host/lib/make
include ${MAKELIBHOME}/GCC.inc
endif
build: ${MAIN}
clean:; rm -fr core *.o latest*
The MAKELIBHOME directory is a place where I store various pieces of makefiles (MINGW32.inc, GCC.inc etc.). The MAKELIBHOME is an environment variable on Windows, but the Netbeans on Linux doesn't understand such kind of environment variables, so I have to assign this variable right in the Makefile before including the pieces.
All is stored in the Git repo.
I am working on several C++ projects on my local computer. They all use some common libs and headers. The file structure is like this:
-bin
-lib
-include
-devel
-project1
-src
-project2
-src
-doc
I am using Eclipse IDE and i set all the relative paths. It compiles the executables to the bin folder and uses libs/includes within the structure. It works fine.
Now I need to import all the projects into an SVN repository so that different people can access and develop codes.
And i wondering if there is a way to have this structure in the SVN server? So when someone checks out a project, he can just start working on it without organising the libs or headers. He will just check out, and all the relative linking will be done.
I am using Eclipse with subclipse plugin.
why u don't use maven? with SVN or GIT it's very good...