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
Been trying to set up django to work with nginx and gunicorn for a few days, followed a digital ocean guide for the setup, tried numerous solutions found in this forum but none worked for me.
This is my first stackoverflow post, if it's miss-formated or poorly written based on how you like to read the posts I'd like to hear it so that I can improve.
Starting gunicorn from the folder
/home/django/virtualenv/sio/SiO
running the command
gunicorn --bind 0.0.0.0:8000 SiO.wsgi:application
works just fine, I've tried setting this to be the sock-folder. But my latest try has been for /home/django/virtualenv/sio/SiO/SiO where the wsgi.py file resides.
when looking at the nginx error log I find
2017/05/03 13:56:34 [emerg] 29248#29248: invalid number of arguments in "proxy_pass" directive in /etc/nginx/sites-enabled/sio:12
2017/05/03 13:58:54 [crit] 29275#29275: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:03:53 [crit] 29275#29275: *4 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:06:02 [crit] 29422#29422: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:11:51 [crit] 29422#29422: *5 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:13:10 [crit] 29422#29422: *9 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:25:34 [crit] 29422#29422: *11 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 14:51:30 [crit] 712#712: *1 connect() to unix:/home/django/virtualenv/sio/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO.sock:/", host: "67.207.75.163"
2017/05/03 15:00:41 [crit] 954#954: *1 connect() to unix:/home/django/virtualenv/sio/SiO/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO/SiO.sock:/", host: "67.207.75.163"
2017/05/03 15:02:00 [crit] 1069#1069: *1 connect() to unix:/home/django/virtualenv/sio/SiO/SiO.sock failed (2: No such file or directory) while connecting to upstream, client: 158.39.197.123, server: 67.207.75.163, request: "GET / HTTP/1.1", upstream: "http://unix:/home/django/virtualenv/sio/SiO/SiO.sock:/", host: "67.207.75.163"
There is no .sock file anywhere in my project. I tried this fix.
Tree view of the project structure:
|-- SiO
| |-- calapp
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | |-- calendar.css
| | | | |-- responsive.css
| | | | `-- sidebar.css
| | | `-- js
| | | |-- calendar.js
| | | `-- jquery-1.12.4.min.js
| | |-- templates
| | | `-- calapp
| | | |-- calendar (copy).html
| | | `-- calendar.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- chart
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | `-- chart.css
| | | `-- js
| | | `-- chart.js
| | |-- templates
| | | `-- chart
| | | `-- ChartView.html
| | |-- admin.py
| | |-- apps.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- CoAdmin
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | |-- 0002_auto_20170413_0316.cpython-35.pyc
| | | | |-- 0003_auto_20170413_1514.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | |-- 0002_auto_20170413_0316.py
| | | |-- 0003_auto_20170413_1514.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- serializers.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | `-- css
| | | `-- signup.css
| | |-- templates
| | | `-- CoAdmin
| | | |-- admin_delete.html
| | | |-- admin_edit.html
| | | |-- admin_overview.html
| | | |-- InnsideSignup.html
| | | |-- password.html
| | | `-- signup.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- core
| | |-- migrations
| | | |-- __pycache__
| | | | `-- __init__.cpython-35.pyc
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | |-- animate.css
| | | | |-- cover.css
| | | | |-- dashboard.css
| | | | |-- network.css
| | | | `-- profile.css
| | | |-- img
| | | | |-- logo.svg
| | | | `-- SiOLogo.png
| | | `-- js
| | | `-- picture.js
| | |-- templates
| | | `-- core
| | | |-- cover.html
| | | |-- dashboard.html
| | | |-- partial_settings_menu.html
| | | |-- password.html
| | | |-- profile.html
| | | `-- settings.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- member
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- forms.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- serializers.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | `-- css
| | | |-- member_overview.css
| | | `-- member_signup.css
| | |-- templates
| | | `-- member
| | | |-- asoc_signup.html
| | | |-- member_confirm_delete.html
| | | |-- member_delete.html
| | | |-- member_edit.html
| | | |-- member_overview.html
| | | `-- member_signup.html
| | |-- admin.py
| | |-- apps.py
| | |-- forms.py
| | |-- __init__.py
| | |-- models.py
| | |-- serializers.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- post
| | |-- migrations
| | | |-- __pycache__
| | | | |-- 0001_initial.cpython-35.pyc
| | | | |-- 0002_auto_20170413_1514.cpython-35.pyc
| | | | |-- 0003_remove_email_sendstatus.cpython-35.pyc
| | | | `-- __init__.cpython-35.pyc
| | | |-- 0001_initial.py
| | | |-- 0002_auto_20170413_1514.py
| | | |-- 0003_remove_email_sendstatus.py
| | | `-- __init__.py
| | |-- __pycache__
| | | |-- admin.cpython-35.pyc
| | | |-- __init__.cpython-35.pyc
| | | |-- mail.cpython-35.pyc
| | | |-- models.cpython-35.pyc
| | | |-- urls.cpython-35.pyc
| | | `-- views.cpython-35.pyc
| | |-- static
| | | |-- css
| | | | `-- post.css
| | | `-- javascript
| | | `-- post.js
| | |-- templates
| | | `-- post
| | | `-- post.html
| | |-- admin.py
| | |-- apps.py
| | |-- __init__.py
| | |-- mail.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | `-- views.py
| |-- __pycache__
| | |-- __init__.cpython-35.pyc
| | |-- settings.cpython-35.pyc
| | |-- urls.cpython-35.pyc
| | `-- wsgi.cpython-35.pyc
| |-- static
| | |-- css
| | | |-- jquery.Jcrop.min.css
| | | `-- SiO.css
| | |-- img
| | | |-- sio-logo.jpg
| | | `-- user.png
| | `-- js
| | |-- date.js
| | |-- ga.js
| | |-- jquery.bullseye-1.0-min.js
| | |-- jquery.Jcrop.min.js
| | |-- jquery.selection.js
| | |-- jquery.typeahead.bundle.js
| | |-- SiO.js
| | `-- SiO.markdown.js
| |-- templates
| | |-- admin
| | | `-- chart_association.html
| | |-- 403.html
| | |-- 404.html
| | |-- 500.html
| | `-- base.html
| |-- __init__.py
| |-- settings.py
| |-- urls.py
| `-- wsgi.py
|-- staticfiles
| |-- admin
| | |-- css
| | | |-- base.css
| | | |-- changelists.css
| | | |-- dashboard.css
| | | |-- fonts.css
| | | |-- forms.css
| | | |-- login.css
| | | |-- rtl.css
| | | `-- widgets.css
| | |-- fonts
| | | |-- LICENSE.txt
| | | |-- README.txt
| | | |-- Roboto-Bold-webfont.woff
| | | |-- Roboto-Light-webfont.woff
| | | `-- Roboto-Regular-webfont.woff
| | |-- img
| | | |-- gis
| | | | |-- move_vertex_off.svg
| | | | `-- move_vertex_on.svg
| | | |-- calendar-icons.svg
| | | |-- icon-addlink.svg
| | | |-- icon-alert.svg
| | | |-- icon-calendar.svg
| | | |-- icon-changelink.svg
| | | |-- icon-clock.svg
| | | |-- icon-deletelink.svg
| | | |-- icon-no.svg
| | | |-- icon-unknown-alt.svg
| | | |-- icon-unknown.svg
| | | |-- icon-yes.svg
| | | |-- inline-delete.svg
| | | |-- LICENSE
| | | |-- README.txt
| | | |-- search.svg
| | | |-- selector-icons.svg
| | | |-- sorting-icons.svg
| | | |-- tooltag-add.svg
| | | `-- tooltag-arrowright.svg
| | `-- js
| | |-- admin
| | | |-- DateTimeShortcuts.js
| | | `-- RelatedObjectLookups.js
| | |-- vendor
| | | |-- jquery
| | | | |-- jquery.js
| | | | |-- jquery.min.js
| | | | `-- LICENSE-JQUERY.txt
| | | `-- xregexp
| | | |-- LICENSE-XREGEXP.txt
| | | |-- xregexp.js
| | | `-- xregexp.min.js
| | |-- actions.js
| | |-- actions.min.js
| | |-- calendar.js
| | |-- cancel.js
| | |-- change_form.js
| | |-- collapse.js
| | |-- collapse.min.js
| | |-- core.js
| | |-- inlines.js
| | |-- inlines.min.js
| | |-- jquery.init.js
| | |-- popup_response.js
| | |-- prepopulate_init.js
| | |-- prepopulate.js
| | |-- prepopulate.min.js
| | |-- SelectBox.js
| | |-- SelectFilter2.js
| | |-- timeparse.js
| | `-- urlify.js
| |-- css
| | |-- animate.css
| | |-- bootstrap-datetimepicker.css
| | |-- bootstrap.min.css
| | |-- calendar.css
| | |-- chart.css
| | |-- cover.css
| | |-- dashboard.css
| | |-- datetimepicker.css
| | |-- jquery.Jcrop.min.css
| | |-- member_overview.css
| | |-- member_signup.css
| | |-- network.css
| | |-- post.css
| | |-- profile.css
| | |-- responsive.css
| | |-- sidebar.css
| | |-- signup.css
| | `-- SiO.css
| |-- fonts
| | |-- glyphicons-halflings-regular.eot
| | |-- glyphicons-halflings-regular.svg
| | |-- glyphicons-halflings-regular.ttf
| | |-- glyphicons-halflings-regular.woff
| | `-- glyphicons-halflings-regular.woff2
| |-- img
| | |-- logo.svg
| | |-- sio-logo.jpg
| | |-- SiOLogo.png
| | `-- user.png
| |-- javascript
| | `-- post.js
| |-- js
| | |-- locales
| | | |-- bootstrap-datetimepicker.ar.js
| | | |-- bootstrap-datetimepicker.bg.js
| | | |-- bootstrap-datetimepicker.ca.js
| | | |-- bootstrap-datetimepicker.cs.js
| | | |-- bootstrap-datetimepicker.da.js
| | | |-- bootstrap-datetimepicker.de.js
| | | |-- bootstrap-datetimepicker.ee.js
| | | |-- bootstrap-datetimepicker.el.js
| | | |-- bootstrap-datetimepicker.es.js
| | | |-- bootstrap-datetimepicker.fi.js
| | | |-- bootstrap-datetimepicker.fr.js
| | | |-- bootstrap-datetimepicker.he.js
| | | |-- bootstrap-datetimepicker.hr.js
| | | |-- bootstrap-datetimepicker.hu.js
| | | |-- bootstrap-datetimepicker.id.js
| | | |-- bootstrap-datetimepicker.is.js
| | | |-- bootstrap-datetimepicker.it.js
| | | |-- bootstrap-datetimepicker.ja.js
| | | |-- bootstrap-datetimepicker.ko.js
| | | |-- bootstrap-datetimepicker.kr.js
| | | |-- bootstrap-datetimepicker.lt.js
| | | |-- bootstrap-datetimepicker.lv.js
| | | |-- bootstrap-datetimepicker.ms.js
| | | |-- bootstrap-datetimepicker.nb.js
| | | |-- bootstrap-datetimepicker.nl.js
| | | |-- bootstrap-datetimepicker.no.js
| | | |-- bootstrap-datetimepicker.pl.js
| | | |-- bootstrap-datetimepicker.pt-BR.js
| | | |-- bootstrap-datetimepicker.pt.js
| | | |-- bootstrap-datetimepicker.ro.js
| | | |-- bootstrap-datetimepicker.rs.js
| | | |-- bootstrap-datetimepicker.rs-latin.js
| | | |-- bootstrap-datetimepicker.ru.js
| | | |-- bootstrap-datetimepicker.sk.js
| | | |-- bootstrap-datetimepicker.sl.js
| | | |-- bootstrap-datetimepicker.sv.js
| | | |-- bootstrap-datetimepicker.sw.js
| | | |-- bootstrap-datetimepicker.th.js
| | | |-- bootstrap-datetimepicker.tr.js
| | | |-- bootstrap-datetimepicker.ua.js
| | | |-- bootstrap-datetimepicker.uk.js
| | | |-- bootstrap-datetimepicker.zh-CN.js
| | | `-- bootstrap-datetimepicker.zh-TW.js
| | |-- bootstrap-datetimepicker.js
| | |-- calendar.js
| | |-- chart.js
| | |-- date.js
| | |-- ga.js
| | |-- jquery-1.12.4.min.js
| | |-- jquery.bullseye-1.0-min.js
| | |-- jquery.Jcrop.min.js
| | |-- jquery.selection.js
| | |-- jquery.typeahead.bundle.js
| | |-- picture.js
| | |-- SiO.js
| | `-- SiO.markdown.js
| `-- rest_framework
| |-- css
| | |-- bootstrap.min.css
| | |-- bootstrap-tweaks.css
| | |-- default.css
| | `-- prettify.css
| |-- docs
| | |-- css
| | | |-- base.css
| | | |-- bootstrap.min.css
| | | |-- bootstrap-theme.min.css
| | | |-- font-awesome-4.0.3.css
| | | |-- highlight.css
| | | `-- jquery.json-view.min.css
| | |-- fonts
| | | |-- fontawesome-webfont.eot
| | | |-- fontawesome-webfont.svg
| | | |-- fontawesome-webfont.ttf
| | | |-- fontawesome-webfont.woff
| | | |-- glyphicons-halflings-regular.eot
| | | |-- glyphicons-halflings-regular.svg
| | | |-- glyphicons-halflings-regular.ttf
| | | |-- glyphicons-halflings-regular.woff
| | | `-- glyphicons-halflings-regular.woff2
| | |-- img
| | | |-- favicon.ico
| | | `-- grid.png
| | `-- js
| | |-- api.js
| | |-- base.js
| | |-- bootstrap.min.js
| | |-- highlight.pack.js
| | |-- jquery-1.10.2.min.js
| | `-- jquery.json-view.min.js
| |-- fonts
| | |-- glyphicons-halflings-regular.eot
| | |-- glyphicons-halflings-regular.svg
| | |-- glyphicons-halflings-regular.ttf
| | |-- glyphicons-halflings-regular.woff
| | `-- glyphicons-halflings-regular.woff2
| |-- img
| | |-- glyphicons-halflings.png
| | |-- glyphicons-halflings-white.png
| | `-- grid.png
| `-- js
| |-- ajax-form.js
| |-- bootstrap.min.js
| |-- coreapi-0.1.0.js
| |-- csrf.js
| |-- default.js
| |-- jquery-1.12.4.min.js
| `-- prettify-min.js
|-- manage.py
`-- requirements.txt
My gunicorn file is located in
/home/django/virtualenv/sio/bin/gunicorn
Content of /etc/systemd/system/gunicorn.service
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=django
Group=www-data
WorkingDirectory=/home/django/virtualenv/sio/SiO
ExecStart=/home/django/virtualenv/sio/bin/gunicorn --workers 3 --bind unix:/home/django/virtualenv/sio/SiO/SiO SiO.wsgi:application
[Install]
WantedBy=multi-user.target
and my /etc/nginx/sites-available/sio file
server {
listen 80;
server_name 67.207.75.163;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /home/django/virtualenv/sio/SiO;
}
location / {
include proxy_params;
proxy_pass http://unix:/home/django/virtualenv/sio/SiO/SiO.sock;
}
}
The site works when trying to run using only the django built inn webserver. When trying to access using gunicorn I get a 502 error.
You're missing ".sock" in this line:
ExecStart=/home/django/virtualenv/sio/bin/gunicorn --workers 3 --bind unix:/home/django/virtualenv/sio/SiO/SiO SiO.wsgi:application
You're binding to a folder instead of a sock file, but you're telling nginx to look for /home/django/virtualenv/sio/SiO/SiO.sock
So, perhaps try this:
ExecStart=/home/django/virtualenv/sio/bin/gunicorn --workers 3 --bind unix:/home/django/virtualenv/sio/SiO/SiO.sock SiO.wsgi:application
EDIT: By the way, I'm a massive fan of this setup and can't recommend it highly enough - http://michal.karzynski.pl/blog/2013/06/09/django-nginx-gunicorn-virtualenv-supervisor/
Making the changes you suggested did not fix the problem, trying the guide you sent in a new VM did how ever fix everything. Thank you! It was excellent, normally digital ocean guides are my go-to but you have convinced me to look other places too :).
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.
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