From b74fd9680c20f8cbdbcf6cdff9ee1074c55fe1c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= <lalinsky@gmail.com>
Date: Thu, 14 Jun 2012 09:58:41 +0200
Subject: [PATCH] Support out-of-source build

http://tickets.musicbrainz.org/browse/LMB-10
https://github.com/metabrainz/libmusicbrainz/issues/1
---
 examples/CMakeLists.txt |    5 ++++-
 src/CMakeLists.txt      |    9 +++++++--
 src/make-c-interface.cc |    8 ++++----
 tests/CMakeLists.txt    |    5 ++++-
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 3e11469..000d4aa 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,4 +1,7 @@
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include)
+INCLUDE_DIRECTORIES(
+	${CMAKE_CURRENT_SOURCE_DIR}/../include
+	${CMAKE_CURRENT_BINARY_DIR}/../include
+)
 LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES})
 
 ADD_EXECUTABLE(cdlookup cdlookup.cc)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 2ee102f..89ab63c 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,5 +1,10 @@
 SET(CMAKE_INCLUDE_CURRENT_DIR ON)
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../include ${NEON_INCLUDE_DIR})
+INCLUDE_DIRECTORIES(
+	${CMAKE_CURRENT_SOURCE_DIR}/..
+	${CMAKE_CURRENT_SOURCE_DIR}/../include
+	${CMAKE_CURRENT_BINARY_DIR}/../include
+	${NEON_INCLUDE_DIR}
+)
 
 SET(_sources Alias.cc Annotation.cc Artist.cc ArtistCredit.cc Attribute.cc CDStub.cc Collection.cc
 	Disc.cc Entity.cc FreeDBDisc.cc HTTPFetch.cc ISRC.cc Label.cc LabelInfo.cc Lifespan.cc List.cc
@@ -13,7 +18,7 @@ ADD_EXECUTABLE(make-c-interface make-c-interface.cc xmlParser.cpp)
 ADD_CUSTOM_COMMAND(
 	OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.cc ${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5/mb5_c.h
 	COMMAND make-c-interface ${CMAKE_CURRENT_SOURCE_DIR} cinterface.xml ${CMAKE_CURRENT_BINARY_DIR} mb5_c.cc mb5_c.h
-	COMMAND ${CMAKE_COMMAND} -E copy_if_different 	${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5
+	COMMAND ${CMAKE_COMMAND} -E copy_if_different 	${CMAKE_CURRENT_BINARY_DIR}/mb5_c.h ${CMAKE_CURRENT_BINARY_DIR}/../include/musicbrainz5/mb5_c.h
 	DEPENDS make-c-interface cinterface.xml *.inc
 )
 
diff --git a/src/make-c-interface.cc b/src/make-c-interface.cc
index 652a65b..70dd6d7 100644
--- a/src/make-c-interface.cc
+++ b/src/make-c-interface.cc
@@ -33,7 +33,7 @@
 
 #include "musicbrainz5/xmlParser.h"
 
-void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include);
+void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include, const std::string& Path);
 void ProcessHeader(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include);
 void ProcessEntity(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include);
 void ProcessClass(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include);
@@ -80,7 +80,7 @@ int main(int argc, const char *argv[])
 				std::string Name=Node.getName();
 
 				if ("boilerplate"==Name)
-					ProcessBoilerplate(Node,Source,Include);
+					ProcessBoilerplate(Node,Source,Include,argv[1]);
 				else if ("header"==Name)
 					ProcessHeader(Node,Source,Include);
 				else if ("declare"==Name)
@@ -156,13 +156,13 @@ void ProcessHeader(const XMLNode& /*Node*/, std::ofstream& Source, std::ofstream
 	Include << os.str() << std::endl;
 }
 
-void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include)
+void ProcessBoilerplate(const XMLNode& Node, std::ofstream& Source, std::ofstream& Include, const std::string& Path)
 {
 	std::ofstream *File=GetFile(Node,Source,Include);
 
 	if (Node.isAttributeSet("file"))
 	{
-		std::string FileName=Node.getAttribute("file");
+		std::string FileName=Path+"/"+Node.getAttribute("file");
 		std::ifstream InFile(FileName.c_str());
 		if (InFile.is_open())
 			*File << InFile.rdbuf() << std::endl;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 645f8ae..8a0b38b 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,4 +1,7 @@
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../include)
+INCLUDE_DIRECTORIES(
+	${CMAKE_CURRENT_SOURCE_DIR}/../include
+	${CMAKE_CURRENT_BINARY_DIR}/../include
+)
 LINK_LIBRARIES(musicbrainz5 ${NEON_LIBRARIES})
 ADD_EXECUTABLE(mbtest mbtest.cc)
 ADD_EXECUTABLE(ctest ctest.c)
-- 
1.7.10

From b5d4f4ea32068e296326438c747faf665c311ddd Mon Sep 17 00:00:00 2001
From: Andy Hawkins <andy@gently.org.uk>
Date: Thu, 14 Jun 2012 09:12:27 +0000
Subject: [PATCH] Fix install when building out of tree

---
 CMakeLists.txt |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 16870b4..958461c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -32,7 +32,7 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.cmake ${CMAKE_CURRENT_SOURCE
 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
 
 FILE(GLOB headers ${CMAKE_CURRENT_SOURCE_DIR}/include/musicbrainz5/*.h)
-INSTALL(FILES ${headers} include/musicbrainz5/mb5_c.h DESTINATION ${INCLUDE_INSTALL_DIR}/musicbrainz5)
+INSTALL(FILES ${headers} ${CMAKE_CURRENT_BINARY_DIR}/include/musicbrainz5/mb5_c.h DESTINATION ${INCLUDE_INSTALL_DIR}/musicbrainz5)
 INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libmusicbrainz5.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
 
 ADD_SUBDIRECTORY(src)
-- 
1.7.10


