1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
From 2b4a7f5d03dc605a9e2c0273d5e8c0d8c4777c07 Mon Sep 17 00:00:00 2001
From: Han Luo <han.luo@gmail.com>
Date: Fri, 31 Aug 2018 02:25:58 -0400
Subject: [PATCH] Fix some issues with CMake - Replace the absolute path
provided by __FILE__ to the relative path - Allow user to pass
CMAKE_INSTALL_PREFIX now - Remove absolute path in src/CMakeLists.txt (Not
necessary)
---
CMakeLists.txt | 6 ++++--
src/CMakeLists.txt | 5 +++++
src/general/Errors.h | 8 ++++++--
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3781ef4..22ca3b1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -79,15 +79,17 @@ endif ()
################################################################################
# Install prefix settings
################################################################################
-SET (CMAKE_INSTALL_PREFIX "../install" CACHE STRING
+if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
+ SET (CMAKE_INSTALL_PREFIX "../install" CACHE STRING
"Install path prefix, prepended onto install directories." FORCE)
+endif()
MARK_AS_ADVANCED (CMAKE_INSTALL_PREFIX)
if (CMAKE_COMPILER_IS_GNUCXX)
#set (CMAKE_CXX_FLAGS "-Wall -Wextra -Wno-unused-parameter -Wold-style-cast")
set (CMAKE_CXX_FLAGS "-g")
endif ()
-
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
################################################################################
# Fortran wrapper options
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index d9437f8..8326ffe 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -21,6 +21,9 @@
cmake_minimum_required(VERSION 2.6)
+# Set property to save the path of src
+set_property(GLOBAL PROPERTY MPPSRC_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
+
#- Add sources for a target
#
# ADD_SOURCES(<target> <source1> [<source2> ...])
@@ -39,6 +42,8 @@ function (add_sources target)
if(NOT IS_ABSOLUTE "${src}")
get_filename_component(src "${src}" ABSOLUTE)
endif()
+ get_property(src_path_local GLOBAL PROPERTY MPPSRC_PATH)
+ file(RELATIVE_PATH src ${src_path_local} ${src})
list(APPEND SRCS "${src}")
endforeach()
# append to global property
diff --git a/src/general/Errors.h b/src/general/Errors.h
index 615989a..81988f7 100644
--- a/src/general/Errors.h
+++ b/src/general/Errors.h
@@ -27,6 +27,10 @@
#ifndef ERRORS_H
#define ERRORS_H
+#ifndef __FILENAME__
+#define __FILENAME__ __FILE__
+#endif
+
//#include <algorithm>
#include <cstdlib>
#include <exception>
@@ -392,7 +396,7 @@ public:
}
}; // class LogicError
-#define LogicError() LogicError(__FILE__, __LINE__)
+#define LogicError() LogicError(__FILENAME__, __LINE__)
/// Reports a "function not implemented" error. Includes file, line number, and
@@ -424,7 +428,7 @@ public:
}
};
-#define NotImplementedError(_func_) NotImplementedError(_func_, __FILE__, __LINE__)
+#define NotImplementedError(_func_) NotImplementedError(_func_, __FILENAME__, __LINE__)
} // namespace Mutation
--
2.18.0
|