I want to separate the source code and object code to a different directory.
The following is my directory tree:
.
|-- bsp
| |-- Makefile
| `-- x86
| |-- begin.s
| |-- dummy.s
| |-- helloos.s
| |-- lowlevel_init.s
| `-- Makefile
|-- buildrules
| |-- builder.rules
| |-- linker.rules
| `-- subdir.rules
|-- configure
| `-- helloos.lds
|-- hypervisor
| |-- font.c
| |-- int.c
| |-- int_entry.s
| |-- Makefile
| |-- mouse.c
| `-- start.c
|-- include
| |-- common.h
| `-- font.h
|-- lib
| |-- lib.s
| `-- Makefile
|-- Makefile
`-- README.md
I want to Create a "obj" subdir on the root(TOP) dir. put all obj file into it.
Like the following:
.
|-- bsp
| |-- Makefile
| `-- x86
| |-- begin.s
| |-- dummy.s
| |-- helloos.s
| |-- lowlevel_init.s
| `-- Makefile
|-- buildrules
| |-- builder.rules
| |-- linker.rules
| `-- subdir.rules
|-- configure
| `-- helloos.lds
|-- hypervisor
| |-- font.c
| |-- int.c
| |-- int_entry.s
| |-- Makefile
| |-- mouse.c
| `-- start.c
|-- include
| |-- common.h
| `-- font.h
|-- lib
| |-- lib.s
| `-- Makefile
|-- Makefile
|-- obj
| |-- begin.o
| |-- dummy.o
| |-- font.o
| |-- helloos.o
| |-- int_entry.o
| |-- int.o
| |-- lib.o
| |-- lowlevel_init.o
| |-- mouse.o
| `-- start.o
`-- README.md
And then, This is my implementation:
%.o: %.c
$(CC) $(CFLAGS) -c -o $(OBJDIR)/$# $<
%.o: %.s
$(AS) $(ASFLAGS) -o $(OBJDIR)/$# $<
but I don't like this implementation.
I want to write it like this :
$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $# $<
$(OBJDIR)/%.o: %.s
$(AS) $(ASFLAGS) -o $# $<
if i do that, Make not follow these rules, but it uses implicit rules.
Thanks you for you help!!!!!!!!!!!!!!!
Welcome any puzzled.
Your implicit rule will work if you use VPATH
VPATH = bsp hypervisor lib
$(OBJDIR)/%.o: %.c
$(CC) $(CFLAGS) -c -o $# $<
http://www.gnu.org/software/make/manual/make.html :
The value of the make variable VPATH specifies a list of directories that make should search.
For example,
VPATH = src:../headers
specifies a path containing two directories, src and ../headers, which make searches in that order.
With this value of VPATH, the following rule,
foo.o : foo.c
is interpreted as if it were written like this:
foo.o : src/foo.c
Related
I would like to understand how to structure my cpp project correctly. I am using the build generator CMAKE. The build system I am using is Ninja. I have 2 main functions in my project. Each main should be compiled into a different executable.
When and why should I use multiple cmake files?
How can I better structure my project?
|-- CMakeLists.txt
|-- README.md
|-- env.csh
|-- include
| |-- Pen.h
| |-- Cup.h
| |-- Clip.h
| |-- Fun.h
| |-- Ins.h
| |-- Ne.h
| `-- Pa.h
|-- libs
|-- src
| |-- Pen.cpp
| |-- Cup.cpp
| |-- Clip.cpp
| |-- Fun.cpp
| |-- Ins.cpp
| |-- Ne.cpp
| |-- Pa.cpp
| |-- main0.cpp
| `-- main1.cpp
`-- tests
`-- test.cpp
You need one add_executable() line for each executable in your project. Try this CMakeLists.txt file (written mostly from memory):
cmake_minimum_required(VERSION 2.8)
project(myproject LANGUAGES CXX)
enable_testing()
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
set(SOURCES
src/Pen.cpp
src/Cup.cpp
src/Clip.cpp
src/Fun.cpp
src/Ins.cpp
src/Ne.cpp
src/Pa.cpp
)
add_executable(main0 src/main0.cpp ${SOURCES})
add_executable(main1 src/main1.cpp ${SOURCES})
add_executable(unittests tests/test.cpp ${SOURCES})
add_test(tests unittests)
Let's say I have such project structure
|-- DynamicLoader
| `-- dmc
| |-- DynamicLoader.h
| |-- Loader
| | |-- DynamicLibrary.cpp
| | |-- DynamicLibrary.h
| | |-- LibraryManager.cpp
| | |-- LibraryManager.h
| |-- Utils
| | |-- Utils.h
| |-- dmc.cpp
| |-- dmc.h
where dmc.h is my pre-compiled header.
I want to use it for example in my source files located in Loader folder like this: #include "dmc/dmc.h
but the intelisense complains about it and I have to use those semantics:
#include "../dmc.h"
is there anyway to achieve this in visual studio? I've seen one project that worked similarly to this but I couldn't figure it out by myself
I am able to locate the specific file by giving the path in Repository().
But the output generated is in the Sconstruct directory instead of in the
variant_dir.
Please let me know how to resolve this issue
Explaining the problem specifically
The tree structure in the project looks as below.
tree .
.
|-- SConstruct
|--Build
| `-- SConscript_unitTest
|--FileB_mock.o
|--FileA.o
|-- _Output
| `-- unit_test
| |--FileA_unittest.o
`-- moduleA
| |-- FileA.cpp
| `-- UnitTest
| |-- FileA_unittest.cpp
| `-- SConscript
`-- moduleB
| |-- FileB.cpp
| `-- UnitTest
| |-- FileB_unittest.cpp
| `-- SConscript
`-- Mocks
`-- moduleA
| |-- FileA_mock.cpp
| `-- FileA_mock.h
`-- moduleB
|-- FileB_mock.cpp
`-- FileB_mock.h
For the above structure,
In the SConstruct i make the call to SConscript_unitTest.
Implementation of Sconscript_unitTest is
'SConscript('#\moduleA\UnitTest\SConscript',
variant_dir = '#_Output\unit_test'), duplicate=0)'
Implementation of moduleA\UnitTest\Sconscript is
Sources = [ 'FileA_unittest.cpp',
'#FileB_mock.cpp',
'#FileA.cpp'
]
Repository( '#\ModuleA', '#\Mocks\ModuleB')
obj_files = Object(Sources)
Program(target_name, obj_files)
As shown in the Heirarchical diagram, FileA_unittest.o falls in the intended variant_dir, but FileB_mock.o and FileA.o are in the root folder.
I am not sure what i have done here is the best mechanism .. as i am translating an existing make project to scons.
Hope i have given enough detail of the problem.
Here's the structure of the folder:
TEST
|-- DIR1
| |-- TEST1.cpp
| `-- TEST1.h
|-- DIR2
| |-- TEST2.cpp
| `-- TEST2.h
`-- main.cpp
After qmake -project, qmake TEST.pro, make, I got:
TEST
|-- DIR1
| |-- TEST1.cpp
| `-- TEST1.h
|-- DIR2
| |-- TEST2.cpp
| `-- TEST2.h
|-- Makefile
|-- TEST
|-- TEST.pro
|-- TEST1.o
|-- TEST2.o
|-- main.cpp
`-- main.o
I want to specify the output path of the .o file generated from .cpp file and put .o file in the same folder of its .cpp file, like:
TEST
|-- DIR1
| |-- TEST1.cpp
| |-- TEST1.o
| `-- TEST1.h
|-- DIR2
| |-- TEST2.cpp
| |-- TEST2.o
| `-- TEST2.h
|-- Makefile
|-- TEST
|-- TEST.pro
|-- main.cpp
`-- main.o
qmake puts all object files in one directory and you cant change it. But you can add this line to your .pro file
OBJECTS_DIR = .obj
Then it will create a directory named obj and put all object files there.
In Zend Framework 1.8, using Zend_Tool, the framework now generates controllers, actions, etc. automatically.
What it does is that it also creates a tests directory when creating a project.
quickstart
|-- application
| |-- Bootstrap.php
| |-- configs
| | `-- application.ini
| |-- controllers
| | |-- ErrorController.php
| | `-- IndexController.php
| |-- models
| `-- views
| |-- helpers
| `-- scripts
| |-- error
| | `-- error.phtml
| `-- index
| `-- index.phtml
|-- library
|-- public
| `-- index.php
`-- tests
|-- application
| `-- bootstrap.php
|-- library
| `-- bootstrap.php
`-- phpunit.xml
So what does it do? How do I actually use it?
I am reading about unit-testing and hopefully this will help understand it more.
Thanks,
Wenbert
You have to create the test folder manually. I followed this tutorial.