diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,13 @@ +# Copyright (c) 2017 The Bitcoin developers + +cmake_minimum_required(VERSION 3.1) +project(BitcoinABC) + +# If ccache is available, then use it. +find_program(CCACHE_FOUND ccache) +if(CCACHE_FOUND) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif(CCACHE_FOUND) + +add_subdirectory(src) diff --git a/cmake/platforms/Win32.cmake b/cmake/platforms/Win32.cmake new file mode 100644 --- /dev/null +++ b/cmake/platforms/Win32.cmake @@ -0,0 +1,20 @@ +# Copyright (c) 2017 The Bitcoin developers + +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX i686-w64-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/platforms/Win64.cmake b/cmake/platforms/Win64.cmake new file mode 100644 --- /dev/null +++ b/cmake/platforms/Win64.cmake @@ -0,0 +1,20 @@ +# Copyright (c) 2017 The Bitcoin developers + +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX x86_64-w64-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,3 @@ +# Copyright (c) 2017 The Bitcoin developers + +add_subdirectory(univalue) diff --git a/src/univalue/CMakeLists.txt b/src/univalue/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/univalue/CMakeLists.txt @@ -0,0 +1,53 @@ +# Copyright (c) 2017 The Bitcoin developers + +cmake_minimum_required(VERSION 3.1) +project(univalue) + +option(UNIVALUE_BUILD_TESTS "Build univalue's unit tests" ON) + +include_directories(include) + +# TODO: Version info +add_library(univalue + lib/univalue.cpp + lib/univalue_get.cpp + lib/univalue_read.cpp + lib/univalue_write.cpp +) + +target_include_directories(univalue PRIVATE lib) + +if(UNIVALUE_BUILD_TESTS) + enable_testing() + + add_executable(unitester_test test/unitester.cpp) + add_test(NAME unitester_test COMMAND unitester_tests) + target_link_libraries(unitester_test univalue) + + target_compile_definitions(unitester_test + PUBLIC JSON_TEST_SRC="${PROJECT_SOURCE_DIR}/test" + ) + + add_executable(json_test test/test_json.cpp) + add_test(NAME json_test COMMAND json_test) + target_link_libraries(json_test univalue) + + add_executable(no_nul_test test/no_nul.cpp) + add_test(NAME no_nul_test COMMAND no_nul_test) + target_link_libraries(no_nul_test univalue) + + add_executable(object_test test/object.cpp) + add_test(NAME object_test COMMAND object_test) + target_link_libraries(object_test univalue) +endif(UNIVALUE_BUILD_TESTS) + +# Generate lib/univalue_escapes.h +add_executable(univalue_gen gen/gen.cpp) + +file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) +add_custom_command( + OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/lib/univalue_escapes.h + COMMAND univalue_gen > ${CMAKE_CURRENT_BINARY_DIR}/lib/univalue_escapes.h + DEPENDS univalue_gen ${CMAKE_CURRENT_SOURCE_DIR}/lib/univalue_escapes.h +) +add_custom_target(generate_univalue_escapes_h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/lib/univalue_escapes.h)