Files are dropped from SOURCES list
Hi,
I have a library project where some classes for legacy reasons have to exist twice, once global and once in a namespace.
Now I'm trying to migrate this project to qmake but the qmake generated Makefile is missing rules for half of the source files.
My project consists of files like class.cpp, containing the implementation of the class, and ns_class.cpp looking like
Code:
namespace mynamespace {
#include "class.cpp"
}
My .pro file contains
Code:
SOURCES += class.cpp ns_class.cpp
but the generated Makefile only has rules for ns_class.o, depending on ns_class.cpp and class.cpp. Dependy tracking or something seems to filter out the class.o/class.cpp rules.
Have I missed something obvious? What can I do to make qmake regard the class.cpp as independent source file?
Re: Files are dropped from SOURCES list
Quote:
Code:
namespace mynamespace {
#include "class.cpp"
}
As a first thought, this may not be a good solution, as any standard header files included inside class.cpp will now be defined under mynamesapce, which will lead to lot of mess.
If you still want to maintain it for some legacy reasons then
1. Change the file extension of cpp file to some like an include file (.h or .inc) and then include this file from both class.cpp and ns_class.cpp. That way qmake will give expected output.
2. You need to take care of the gaurd include macros (if used in the first place)
Here is an exmaple
Code:
//legacy.pro
HEADERS += \
legacy_class.h \
ns_legacy_class.h
SOURCES += \
main.cpp \
legacy_class.cpp \
ns_legacy_class.cpp
OTHER_FILES += \
legacy_class.inc
//legacy_class.h
#ifndef LEGACY_CLASS_H
#define LEGACY_CLASS_H
class legacy_class
{
public:
legacy_class();
};
#endif // LEGACY_CLASS_H
//ns_legacy_class.h
#ifndef NS_LEGACY_CLASS_H
#define NS_LEGACY_CLASS_H
namespace mynamespace {
#ifdef LEGACY_CLASS_H
#undef LEGACY_CLASS_H
#include "legacy_class.h"
#define LEGACY_CLASS_H
#else
#include "legacy_class.h"
#endif
}
#endif // NS_LEGACY_CLASS_H
//legacy_class.cpp
#include "legacy_class.inc"
//main.cpp
#include "legacy_class.h"
#include "ns_legacy_class.h"
int main(int, char**)
{
legacy_class A;
mynamespace::legacy_class B;
}
//ns_legacy_class.cpp
namespace mynamespace {
#ifdef LEGACY_CLASS_H
#undef LEGACY_CLASS_H
#include "legacy_class.inc"
#define LEGACY_CLASS_H
#else
#include "legacy_class.inc"
#endif
}
//legacy_class.inc
#include "legacy_class.h"
legacy_class::legacy_class()
{
;
}
Re: Files are dropped from SOURCES list
Quote:
Originally Posted by
Santosh Reddy
As a first thought, this may not be a good solution, as any standard header files included inside class.cpp will now be defined under mynamesapce, which will lead to lot of mess.
Okay, I admit, I've oversimplified the description of my real implementation here. I have taken care of this, but thanks for pointing out.
Quote:
Originally Posted by
Santosh Reddy
If you still want to maintain it for some legacy reasons then
1. Change the file extension of cpp file to some like an include file (.h or .inc) and then include this file from both class.cpp and ns_class.cpp. That way qmake will give expected output.
2. You need to take care of the gaurd include macros (if used in the first place)
Thanks a lot. That way it worked.