Configuration files in separate directory in case of Autotools - makefile

I am implementing CPPUTEST for my application along with Autotools, but the final makefile generated in subdirectories is not able to make the final build.
Folder Structure:
|
+- Build_output: holds executable for CPPUTEST
+- Configure : holds `configure.ac` and `Makefile.am`
+- Src: contains source files that contain functions and makefile.am
+- Test: contains test file
+- build: shell script for creating executables.
Snapshot added: build structure
build structure continue
Usually I see example of autotools every where configuration files is kept outside, not inside the configure folder.
Configure.ac inside configure folder:
AC_INIT([cpputest], [1.0], [])
AM_INIT_AUTOMAKE([
-Wall -Werror foreign subdir-objects
])
AC_PROG_CXX
AC_CONFIG_FILES([
Makefile
../src/Makefile
../test/Makefile
])
AC_OUTPUT
Makefile.am inside configure folder:
SUBDIRS = \
../src \
../test
Shell script present outside "build"
#!/bin/sh
cd configure
autoreconf -i
./configure
make check
When I run my shell script, the make file is getting generated inside src and test folder but when I try make check
it executes cd ../.. ---> screenshot attached
./build execution
Is there any other option needed to add in configure.ac or makefile.am ?

Related

Creating a CMakeLists.txt with header and mains

I have divided my program in 3 folders: build, include, and src.
Build is where I want all the files created from the Makefile to go, include contains a "file.h", and src contains a "file.c" and "main.c".
I have written this in the CMakeLists.txt file:
cmake_minimum_required (VERSION 3.5.1)
project(Listas_interlazadas)
include_directories(${include})
add_executable(ejec
src/main.c
src/listas.c
include/listas.h
)
Nonetheless, I believe I should somehow include the src folder. Also, how do I send all files to the build folder? From the terminal, right?
Thanks.
Your code need some minor reworks.
The command include_directories must point to an valid path
Add header files only in case they are not included in any of your source files
Assume the following structure of your project:
project
+--source
| +--CMakeLists.txt
| +--src
| | +--main.c
| | +--listas.c
| +--include
| +--listas.h
+--build
Reworked CMakeLists.txt
cmake_minimum_required (VERSION 3.5.1)
project(Listas_interlazadas)
include_directories(include)
add_executable(ejec
src/main.c
src/listas.c
)
Back to your questions:
Add the sources: You already inserted the required source files. See add_executable.
Copy sources to build folder: This is not necessary.
To build your project, you have to run cmake and make (or nmake on windows).
Steps:
Open a command shell
Move to the build folder
Run: cmake ../source
Run: make
Some important parts of a CMakeLists.txt

No rule to make target 'mesh2D.h', needed by 'all-am'

I have the following project tree :
src
├── Converters
├── datamodel
Inside datamodel/ I have a header that I want to include in a source cpp file inside Converters/.
However I get the following error :
No rule to make target 'mesh2D.h', needed by 'all-am'
This is my automake Makefile.am inside Converters/:
include $(top_srcdir)/adm_local/unix/make_common_start.am
AM_CPPFLAGS+= \
-I$(top_srcdir)/src/datamodel
libSource_SOURCES=\
source.cpp \
source.h
include_HEADERS=\
mesh2D.h
SUBDIRS=
include $(top_srcdir)/adm_local/unix/make_common_end.am
Thanks for your help!
I would move the
include_HEADERS = mesh2D.h
line to datamodel/Makefile.am if you are using recursive make, or
include_HEADERS += %reldir%/mesh2D.h
to datamodel/Makefile-files if you use a single Makefile.am with per-directory includes or
include_HEADERS += datamodel/mesh2D.h
if you are using a single Makefile.am without per-directory includes.
Note that using include_HEADERS will install the mesh2D.h file into /usr/local/include. If mesh2D.h is just needed to compile your program, use noinst_HEADERS instead of include_HEADERS to include mesh2D.h in the distribution tarball (make dist) without installing it (make install).

Copy folder into subdirectory in CMake on Windows

I have a CMake project using Makefiles on Windows, with a folder structure that looks like this (the build takes place in build):
project
|- build
|- ...
|- otherfolder
|- stuff
|- more stuff
As a build step (pre- or post doesn't matter), I want to make a copy of project into build (excluding the build folder), like so:
project
|- build
|- ...
|- project
|- otherfolder
|- stuff
|- more stuff
|- otherfolder
|- stuff
|- more stuff
Other options might be acceptable as well, e.g. copying to a temporary directory outside the project root before moving it into place, but CMake seemingly has no builtin support for generating temporary directories.
Things I've tried: xcopy has support for excluding certain files and directories, but refuses to copy even if I explicitly exclude the build folder. cmake -E copy_directory does not (from what I'm able to find) support excluding certain directories.
CMake's file(COPY ... PATTERN build EXCLUDE ... copies successfully, but it runs at CMake configure time and I haven't been able to find a way to make it run at build time.
I might resort to using Python and shutil, but it would be nice if it could be done without additional dependencies, so I'd prefer a batch file solution.
There are several ways for doing selectable directory copiing.
You can use cmake -P for execute cmake script at any time. E.g:
copy_to_build.cmake:
file(COPY . DESTINATION build PATTERN build EXCLUDE)
CMakeLists.txt:
add_custom_command(... COMMAND cmake -P copy_to_build.cmake)
You can prepare list of subdirectories (and files) at configuration stage, and then copy every element of that list using xcopy. This approach uses fact, that everything outside of build directory is not changed. Here iteration is done on configuration stage (by CMake). I am not sure, whether "for" loop works under COMMAND of add_custom_command. If it works, you can use it for iterate over entries in the shell.
CMakeLists.txt:
# List of elements in source directory.
file(GLOB entries RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
# List of commands for pass to `add_custom_command` as is.
# `COMMAND` keyword is included into list.
set(copy_commands)
foreach(entry ${entries})
list(APPEND copy_commands COMMAND xcopy /s /i
${CMAKE_CURRENT_SOURCE_DIR}/${entry} ${CMAKE_CURRENT_SOURCE_DIR}/build/${entry}
endforeach()
add_custom_command(... ${copy_commands})

GCC dependencies generation full path

In a makefile I am trying to build the list of dependencies for a cpp file. This is the structure of the makefile:
DEPS=dep_file
build:
$(MAKE) dep_file;
.....
dep_file:
#$(GXX) -MM $(file_path) | $(SED) 's/\.o:/.cpp.html:/' >$(DEPS)
I am getting this error when caling the build target for the file CC_Interface.cpp:
/prj/comp/cc/base/src/CC_Interface.h:42:17: CMF.h: No such file or directory
/prj/comp/cc/base/src/CC_Interface.h:43:25: Data.h: No such file or directory
/prj/comp/cc/base/src/CC_Interface.h:44:26: UTMsg.h: No such file or directory
/prj/comp/cc/base/src/CC_Interface.cpp:53:26: bb/Elem.hpp: No such file or directory
/prj/comp/cc/base/src/CC_Interface.cpp:56:18: BB.hpp: No such file or directory
...............
In /prj/comp/cc/base/src I have CC_Interface.h/cpp.
In /prj/comp/bb/ I have Elem.hpp
I want to obtain the full path when building the file with dependencies in the dep_file target from makefile. I was triyng -M, -MM, -MM -MT but it doesn't work.
There is a section in the manual on generating prerequisites automatically. You may not need to follow the whole thing, but at least follow the general setting up of targets, prereqs, and recipe.

Makefile, main function, ClassNotFound

I have a Java program, and write a makefile to compile it on Linux.
My project organized like this (Run.java is the main entry)
Program -
Src -
(package)adb.Bing_WebResults
Run.java
(package)adb.jsonModel
*.java
(package)adb.models
*.java
bin -
lib -
gson.jar
commons.jar
resource -
*.txt
This is my makefile:
# My project require 3 parameters from user input.
default: Run.class
Run.class: src/adb/Bing_WebResults/Run.java
javac -sourcepath src/ -classpath lib/*.jar -d bin/ src/adb/Bing_WebResults/*.java src/adb/jsonModels/*.java src/adb/models/*.java
run:
java -classpath bin/:lib/*.jar Run "$(ARG1)" "$(ARG2)" "$(ARG3)"
When I use "make run" command in Linux terminate, exception shows that "Could not find the main class: Run"
Are there something wrong with my makefile? Wrong path or something?
There are many things that could potentially be wrong, but the most apparent issues are the incorrect dependencies of the targets in your makefile.
First of all, the target run should have a dependency on Run.class. If you do make run then make looks at the target called run. In your makefile, this target does not have any dependencies defined, and it will execute the line java ... without checking whether the actual compiled class Run.class exists. As a consequence, if you do make run from a clean situation, your source code will not be compiled and the java command will fail because the compiled class is missing.
Your dependency of default on Run.class is incorrect as well, because Run.class will exist in the bin directory, not in the working directory. The line below mentions the target Run.class as well.
There are several ways to improve your makefile. See below an example of corrected code with some variables added to avoid repeated expressions. This approach is a matter of style and preference though.
BINDIR := bin
RUNCLASS := Run
RUNBINARY := $(BINDIR)/$(RUNCLASS).class
SRCDIR := src/adb/Bing_WebResults
RUNSRC := $(SRCDIR)/$(RUNCLASS).java
# Note: the default target below is superfluous at this moment
default: $(RUNBINARY)
$(RUNBINARY): $(RUNSRC)
javac -sourcepath src/ -classpath lib/*.jar -d $(BINDIR) $(SRCDIR)/*.java src/adb/jsonModels/*.java src/adb/models/*.java
run: $(RUNBINARY)
java -classpath $(BINDIR):lib/*.jar $(RUNCLASS) "$(ARG1)" "$(ARG2)" "$(ARG3)"
This works for me in a simplified, comparable setup -- it might work for you as well. Looking at the snippet you provided, there are most likely other dependencies or changes that need to be added to complete your makefile correctly. Potentially, you might have to add package information to your run command and dependency expressions, but that depends on your source code. Your post does not contain enough information to provide a complete solution.
P.S.: Do not forget to replace spaces by tabs if you copy this code to your own makefile.
At last you need to specify the package when running since you dont seem to have the main class in default package.
java -classpath bin com.example.Run arg1 arg2 ...
It turns out that two points should be noticed:
(1) Run is in a package, so it should be "adb.Bing_WebResults.Run.class" in makefile.
(2) external jar files should be concatenated by : (e.g. lib/a.jar: lib/b.jar)

Resources