mirror of
https://github.com/nlohmann/json
synced 2024-11-26 22:00:07 +00:00
⚡ cmake compile time reduce using cotire
- Add prefix header - Include catch.hpp - Include json.hpp - Replace private with public for all json_unit files - Move `unit.cpp` to an object library - cotire issue: strip whitespace from CMAKE_INCLUDE_SYSTEM_FLAG_CXX
This commit is contained in:
parent
0200f2dc62
commit
85ce4d7b53
@ -16,6 +16,8 @@ set(JSON_CONFIGVERSION_FILENAME "${JSON_PACKAGE_NAME}ConfigVersion.cmake")
|
|||||||
set(JSON_CONFIG_DESTINATION "cmake")
|
set(JSON_CONFIG_DESTINATION "cmake")
|
||||||
set(JSON_INCLUDE_DESTINATION "include/nlohmann")
|
set(JSON_INCLUDE_DESTINATION "include/nlohmann")
|
||||||
|
|
||||||
|
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
# create and configure the library target
|
# create and configure the library target
|
||||||
add_library(${JSON_TARGET_NAME} INTERFACE)
|
add_library(${JSON_TARGET_NAME} INTERFACE)
|
||||||
target_include_directories(${JSON_TARGET_NAME} INTERFACE
|
target_include_directories(${JSON_TARGET_NAME} INTERFACE
|
||||||
|
4008
cmake/cotire.cmake
Normal file
4008
cmake/cotire.cmake
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,8 +1,16 @@
|
|||||||
|
add_library(catch_main OBJECT
|
||||||
|
"src/unit.cpp"
|
||||||
|
)
|
||||||
|
set_target_properties(catch_main PROPERTIES
|
||||||
|
CXX_STANDARD 11
|
||||||
|
CXX_STANDARD_REQUIRED ON
|
||||||
|
)
|
||||||
|
target_include_directories(catch_main PRIVATE "thirdparty/catch")
|
||||||
|
|
||||||
# The unit test executable.
|
# The unit test executable.
|
||||||
set(JSON_UNITTEST_TARGET_NAME "json_unit")
|
set(JSON_UNITTEST_TARGET_NAME "json_unit")
|
||||||
add_executable(${JSON_UNITTEST_TARGET_NAME}
|
add_executable(${JSON_UNITTEST_TARGET_NAME}
|
||||||
"thirdparty/catch/catch.hpp"
|
$<TARGET_OBJECTS:catch_main>
|
||||||
"src/unit.cpp"
|
|
||||||
"src/unit-algorithms.cpp"
|
"src/unit-algorithms.cpp"
|
||||||
"src/unit-allocator.cpp"
|
"src/unit-allocator.cpp"
|
||||||
"src/unit-capacity.cpp"
|
"src/unit-capacity.cpp"
|
||||||
@ -43,13 +51,33 @@ add_executable(${JSON_UNITTEST_TARGET_NAME}
|
|||||||
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
|
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
|
||||||
CXX_STANDARD 11
|
CXX_STANDARD 11
|
||||||
CXX_STANDARD_REQUIRED ON
|
CXX_STANDARD_REQUIRED ON
|
||||||
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
||||||
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if(MSVC)
|
||||||
|
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
|
||||||
|
COMPILE_DEFINITIONS "_SCL_SECURE_NO_WARNINGS"
|
||||||
|
COMPILE_OPTIONS "/EHsc;$<$<CONFIG:Release>:/Od>"
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch")
|
target_include_directories(${JSON_UNITTEST_TARGET_NAME} PRIVATE "src" "thirdparty/catch")
|
||||||
target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME})
|
target_link_libraries(${JSON_UNITTEST_TARGET_NAME} ${JSON_TARGET_NAME})
|
||||||
|
|
||||||
|
include(cotire OPTIONAL)
|
||||||
|
|
||||||
|
if(COMMAND cotire)
|
||||||
|
set_target_properties(${JSON_UNITTEST_TARGET_NAME} PROPERTIES
|
||||||
|
COTIRE_ADD_UNITY_BUILD FALSE
|
||||||
|
COTIRE_CXX_PREFIX_HEADER_INIT "src/prefix.hpp"
|
||||||
|
)
|
||||||
|
# HACK - CMAKE_INCLUDE_SYSTEM_FLAG_CXX has a trailing space, which Cotire doesn't strip
|
||||||
|
# Technically, this fix should go in cotire.cmake. TODO - submit a pull request upstream.
|
||||||
|
if (CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
|
||||||
|
string (STRIP "${CMAKE_INCLUDE_SYSTEM_FLAG_CXX}" CMAKE_INCLUDE_SYSTEM_FLAG_CXX)
|
||||||
|
endif()
|
||||||
|
cotire(${JSON_UNITTEST_TARGET_NAME})
|
||||||
|
endif()
|
||||||
|
|
||||||
add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default"
|
add_test(NAME "${JSON_UNITTEST_TARGET_NAME}_default"
|
||||||
COMMAND ${JSON_UNITTEST_TARGET_NAME}
|
COMMAND ${JSON_UNITTEST_TARGET_NAME}
|
||||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||||
|
7
test/src/prefix.hpp
Normal file
7
test/src/prefix.hpp
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#define private public
|
||||||
|
#include "json.hpp"
|
||||||
|
using nlohmann::json;
|
@ -26,16 +26,17 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <array>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
|
||||||
using nlohmann::json;
|
using nlohmann::json;
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace udt
|
namespace udt
|
||||||
{
|
{
|
||||||
enum class country
|
enum class country
|
||||||
|
Loading…
Reference in New Issue
Block a user