Skip to content

Commit

Permalink
Add option to override build type
Browse files Browse the repository at this point in the history
- glog_bench in Release configuration produces better results on Windows
  • Loading branch information
tusharpm committed Dec 31, 2016
1 parent 850e8c6 commit 92a031b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
31 changes: 17 additions & 14 deletions external/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,30 @@ On a prompt, run the following
git submodule update --init
cmake -P build_and_run.cmake
```
Optionally, the CMake generator can be overridden using `-DGenerator=<generator name>`.
Ensure it goes before `-P`.
Optionally:
- The build configuration can be overridden using `-DConfiguration=<config name>`. Use `Release` on Windows for better results.
- The CMake generator can be overridden using `-DGenerator=<generator name>`. Use `Ninja` for faster builds.

Ensure these go before `-P`.

The cmake script builds Gflags, Glog and the dependent test projects: glog_bench and glog_example.
After the build process, it runs the test projects and shows the relevant output.
#### Sample result
```
running T:/GitRepo/loguru/external/build/glog_bench;ERROR_QUIET
LOG(WARNING) << string (buffered): 73.695 +- 1.548 us per call
LOG(WARNING) << float (buffered): 83.216 +- 0.986 us per call
LOG(WARNING) << string (unbuffered): 79.280 +- 2.453 us per call
LOG(WARNING) << float (unbuffered): 87.755 +- 0.762 us per call
LOG(WARNING) << string (buffered): 29.347 +- 0.303 us per call
LOG(WARNING) << float (buffered): 31.816 +- 0.103 us per call
LOG(WARNING) << string (unbuffered): 31.926 +- 0.139 us per call
LOG(WARNING) << float (unbuffered): 34.603 +- 0.136 us per call
running T:/GitRepo/loguru/external/build/glog_example
I1231 14:49:09.042631 4020 glog_example.cpp:10] Hello from main.cpp!
I1231 14:49:09.044632 4020 glog_example.hpp:14] complex_calculation started
I1231 14:49:09.044632 4020 glog_example.hpp:15] Starting time machine...
W1231 14:49:09.245019 4020 glog_example.hpp:17] The flux capacitor is not getting enough power!
I1231 14:49:09.646394 4020 glog_example.hpp:19] Lighting strike!
E1231 14:49:10.047559 10976 glog_example.hpp:23] We ended up in 1985!
I1231 14:49:10.048560 4020 glog_example.hpp:25] complex_calculation stopped
I1231 14:49:10.048560 4020 glog_example.cpp:12] main function about to end!
I1231 17:03:14.299798 8852 glog_example.cpp:10] Hello from T:\GitRepo\loguru\external\test\glog_example.cpp!
I1231 17:03:14.301300 8852 glog_example.hpp:14] complex_calculation started
I1231 17:03:14.301300 8852 glog_example.hpp:15] Starting time machine...
W1231 17:03:14.501893 8852 glog_example.hpp:17] The flux capacitor is not getting enough power!
I1231 17:03:14.902706 8852 glog_example.hpp:19] Lighting strike!
E1231 17:03:15.303464 7036 glog_example.hpp:23] We ended up in 1985!
I1231 17:03:15.303964 8852 glog_example.hpp:25] complex_calculation stopped
I1231 17:03:15.303964 8852 glog_example.cpp:12] main function about to end!
```
There are various environment-dependent variables in the result. YMMV.

Expand Down
15 changes: 11 additions & 4 deletions external/build_and_run.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ macro(EXEC_CMD_CHECK)
endif()
endmacro()

# pass in command-line to override the default generator (ex. -DGenerator=Ninja)
# to override the default configuration: ex. -DConfiguration=Release
if(DEFINED Configuration)
list(APPEND CMAKE_EXTRA_ARGS -DCMAKE_BUILD_TYPE=${Configuration})
endif()
# to override the default generator: ex. -DGenerator=Ninja
if(DEFINED Generator)
set(CMAKE_GENERATOR_ARG "-G${Generator}")
list(APPEND CMAKE_EXTRA_ARGS "-G${Generator}")
endif()

set(BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
Expand All @@ -26,10 +30,13 @@ set(BUILD_DIR ${CMAKE_CURRENT_LIST_DIR}/build)
EXEC_CMD_CHECK(${CMAKE_COMMAND} -E make_directory ${BUILD_DIR})

# cd build && cmake .. && cd -
EXEC_CMD_CHECK(${CMAKE_COMMAND} ${CMAKE_GENERATOR_ARG} ${CMAKE_CURRENT_LIST_DIR} WORKING_DIRECTORY ${BUILD_DIR})
EXEC_CMD_CHECK(${CMAKE_COMMAND} ${CMAKE_EXTRA_ARGS} ${CMAKE_CURRENT_LIST_DIR} WORKING_DIRECTORY ${BUILD_DIR})

if(DEFINED Configuration)
set(CMAKE_BUILD_EXTRA_ARGS --config ${Configuration})
endif()
# platform-independent equivalent of `make`
EXEC_CMD_CHECK(${CMAKE_COMMAND} --build ${BUILD_DIR})
EXEC_CMD_CHECK(${CMAKE_COMMAND} --build ${BUILD_DIR} ${CMAKE_BUILD_EXTRA_ARGS})

# ./glog_bench 2>/dev/null
EXEC_CMD_CHECK(${BUILD_DIR}/glog_bench ERROR_QUIET)
Expand Down

0 comments on commit 92a031b

Please sign in to comment.