Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d3cff1b

Browse files
committedOct 3, 2015
Exposed compile flags through CMake and improved debugging
1 parent 76770db commit d3cff1b

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed
 

‎CMakeLists.txt

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ find_package(Boost REQUIRED COMPONENTS filesystem system)
1919

2020
# Find SFML
2121
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/deps/SFML/cmake/Modules" ${CMAKE_MODULE_PATH})
22-
find_package(SFML 2 REQUIRED COMPONENTS graphics window system audio)
22+
if(WIN32)
23+
find_package(SFML 2 REQUIRED COMPONENTS graphics window system audio main)
24+
else()
25+
find_package(SFML 2 REQUIRED COMPONENTS graphics window system audio)
26+
endif()
2327

2428
# ChessPlusPlus
2529
if(APPLE) # Application bundle if on an apple machine
@@ -66,9 +70,15 @@ if(NOT APPLE OR NOT BUILD_APPBUNDLE)
6670
file(COPY config/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/)
6771
file(COPY res/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/res/)
6872
endif()
69-
add_executable(ChessPlusPlus
70-
"src/Main.cpp"
71-
)
73+
if(WIN32)
74+
add_executable(ChessPlusPlus WIN32
75+
"src/Main.cpp"
76+
)
77+
else()
78+
add_executable(ChessPlusPlus
79+
"src/Main.cpp"
80+
)
81+
endif()
7282
endif()
7383
set_property(TARGET ChessPlusPlus PROPERTY CXX_STANDARD 14)
7484
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
@@ -88,5 +98,27 @@ if(SFML_STATIC_LIBRARIES)
8898
target_link_libraries(ChessPlusPlus z bz2)
8999
endif()
90100

101+
# options
102+
if(WIN32)
103+
set(CHESSPP_REDIRECT_OUTPUT_DEFAULT ON)
104+
else()
105+
set(CHESSPP_REDIRECT_OUTPUT_DEFAULT OFF)
106+
endif()
107+
option(CHESSPP_REDIRECT_OUTPUT "Redirects output to files instead of stdout and stderr" ${CHESSPP_REDIRECT_OUTPUT_DEFAULT})
108+
if(CHESSPP_REDIRECT_OUTPUT)
109+
target_compile_definitions(ChessPlusPlus
110+
PRIVATE CHESSPP_REDIRECT_OUTPUT
111+
)
112+
endif()
113+
include(CMakeDependentOption)
114+
CMAKE_DEPENDENT_OPTION(CHESSPP_TRUNC_LOGS "Truncate the log files at the start of the program" ON
115+
"CHESSPP_REDIRECT_OUTPUT" ON
116+
)
117+
if(CHESSPP_TRUNC_LOGS)
118+
target_compile_definitions(ChessPlusPlus
119+
PRIVATE CHESSPP_TRUNC_LOGS
120+
)
121+
endif()
122+
91123
# Divvy out work to subdirectories
92124
add_subdirectory("src/")

‎src/Debug.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@ class LogUtil
142142
std::streambuf *clogbuf {log ? std::clog.rdbuf(&logbuf) : std::clog.rdbuf()}
143143
, *cerrbuf {err ? std::cerr.rdbuf(&errbuf) : std::cerr.rdbuf()}
144144
, *coutbuf {out ? std::cout.rdbuf(&outbuf) : std::cout.rdbuf()};
145-
LogUtil() = default;
145+
LogUtil()
146+
{
147+
//Force file output to appear instantly so crashes don't swallow buffered content
148+
logbuf.pubsetbuf(0, 0);
149+
errbuf.pubsetbuf(0, 0);
150+
outbuf.pubsetbuf(0, 0);
151+
}
146152
LogUtil(LogUtil const &) = delete;
147153
LogUtil(LogUtil &&) = delete;
148154
LogUtil &operator=(LogUtil const &) = delete;

‎src/Main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919
*/
2020
int main(int nargs, char const *const *args)
2121
{
22+
#ifdef CHESSPP_REDIRECT_OUTPUT
2223
LogUtil::enableRedirection();
24+
#endif
2325

2426
try
2527
{
@@ -38,4 +40,5 @@ int main(int nargs, char const *const *args)
3840
std::clog << typeid(e).name() << " caught in main: " << e.what() << std::endl;
3941
return -1;
4042
}
43+
std::clog << "Exiting normally from main" << std::endl;
4144
}

‎src/config/Configuration.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ namespace chesspp
2020
//<.app>/Contents/Resources/res/img... should be where resources are stored.
2121
std::string Configuration::executablePath()
2222
{
23-
2423
char buf[1024];
2524
std::uint32_t size = sizeof(buf);
2625
memset(buf, 0, size);

0 commit comments

Comments
 (0)
Please sign in to comment.