diff --git a/CMakeLists.txt b/CMakeLists.txt index 7620b08..ff79fc6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,10 +2,23 @@ list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake") cmake_minimum_required(VERSION 3.4.1) +if (WIN32) +# "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8 +add_definitions( "-D_GLIBCXX_USE_NANOSLEEP=1" ) +add_definitions( "-DWIN32_LEAN_AND_MEAN" ) +endif() + +#target_compile_options(gmock-matchers_test PRIVATE "-Wa,-mbig-obj") + + #SET(CMAKE_C_COMPILER /path/to/c/compiler) #SET(CMAKE_CXX_COMPILER /path/to/cpp/compiler) -SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -F/Library/Frameworks -pthread") -#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address") +if (WIN32) + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj -O2 -fPIC -std=c++14 -F/Library/Frameworks -pthread -lcrypto -lcrypt32") +else() + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -F/Library/Frameworks -pthread") +endif() +#SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}-fsanitize=address") #SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -std=c++14 -F/Library/Frameworks -pthread -fsanitize=address") # TODO: way to enable sanitize? get runtime error with this on project(MoneroCppLibrary) @@ -102,12 +115,18 @@ find_package(OpenSSL REQUIRED) message(STATUS "Using OpenSSL include dir at ${OPENSSL_INCLUDE_DIR}") include_directories(${OPENSSL_INCLUDE_DIR}) + if(STATIC AND NOT IOS) if(UNIX) set(OPENSSL_LIBRARIES "${OPENSSL_LIBRARIES};${CMAKE_DL_LIBS};${CMAKE_THREAD_LIBS_INIT}") endif() endif() +if (WIN32) + list(APPEND OPENSSL_LIBRARIES ws2_32 crypt32) +endif() + + ############ # libsodium ############ @@ -173,14 +192,26 @@ set_target_properties(epee PROPERTIES IMPORTED_LOCATION # Unbound find_package(Unbound) -include_directories(${UNBOUND_INCLUDE_DIR}) -if ("${UNBOUND_LIBRARIES}" MATCHES "libunbound") - message(STATUS "Using libunbound: ${UNBOUND_LIBRARIES}") - add_library(unbound SHARED IMPORTED) - set_target_properties(unbound PROPERTIES IMPORTED_LOCATION - ${UNBOUND_LIBRARIES}) + +if(NOT UNBOUND_INCLUDE_DIR) + die("Could not find libunbound") +else() + message(STATUS "Found libunbound include (unbound.h) in ${UNBOUND_INCLUDE_DIR}") + if(UNBOUND_LIBRARIES) + message(STATUS "Found libunbound library") + include_directories(${UNBOUND_INCLUDE_DIR}) + if (WIN32) + add_library(unbound STATIC IMPORTED) + else() + add_library(unbound SHARED IMPORTED) + endif() + set_target_properties(unbound PROPERTIES IMPORTED_LOCATION ${UNBOUND_LIBRARIES}) + else() + die("Found libunbound includes, but could not find libunbound library. Please make sure you have installed libunbound or libunbound-dev or the equivalent") + endif() endif() + add_library(rpc_base STATIC IMPORTED) set_target_properties(rpc_base PROPERTIES IMPORTED_LOCATION ${MONERO_PROJECT_BUILD}/src/rpc/librpc_base.a) @@ -371,7 +402,6 @@ if (BUILD_SAMPLE) multisig version randomx - dl epee hardforks cncrypto @@ -385,7 +415,11 @@ if (BUILD_SAMPLE) ${SODIUM_LIBRARY} ${HIDAPI_LIBRARIES} ${EXTRA_LIBRARIES} + ) + if (NOT WIN32) + target_link_libraries(sample_code dl) + endif() endif() ######################## @@ -420,7 +454,6 @@ if (BUILD_SCRATCHPAD) multisig version randomx - dl epee hardforks cncrypto @@ -435,4 +468,8 @@ if (BUILD_SCRATCHPAD) ${HIDAPI_LIBRARIES} ${EXTRA_LIBRARIES} ) + if (NOT WIN32) + target_link_libraries(sample_code dl) + endif() + endif() diff --git a/README.md b/README.md index e2994b5..499a700 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,42 @@ For example, [monero-java](https://github.com/monero-ecosystem/monero-java) comp 5. Build monero-project to create .a libraries, e.g.: `make release-static -j8` 6. Link to this library's source files in your application or build as a shared library in ./build/: `cd $MONERO_CPP && ./bin/build_libmonero_cpp.sh` +## Instructions for building libmonero-cpp.dll on Windows + +1. Download and install [MSYS2](https://www.msys2.org/). +2. Press windows button and type ```MSYS2 MINGW64``` for 64 bit systems or ```MSYS2 MINGW32``` for 32 bit. +3. Update packages: + ```pacman -Syu``` +4. Install dependencies + For 64 bit + ``` + pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-unbound mingw-w64-x86_64-protobuf git mingw-w64-x86_64-libusb + ``` + For 32 bit + ``` + pacman -S mingw-w64-i686-toolchain make mingw-w64-i686-cmake mingw-w64-i686-boost mingw-w64-i686-openssl mingw-w64-i686-zeromq mingw-w64-i686-libsodium mingw-w64-i686-hidapi mingw-w64-i686-unbound mingw-w64-i686-protobuf git mingw-w64-i686-libusb + ``` +5. Clone repo + ``` + git clone --recurse-submodules https://github.com/monero-ecosystem/monero-cpp.git + ``` +6. Update submodules + ``` + cd ./monero-cpp && ./bin/update_submodules.sh + ``` +7. ```export MONERO_CPP=path/to/monero-cpp``` +8. ```cd $MONERO_CPP/external/monero-project``` +9. Build monero-project for 64 bit + ``` + make release-static-win64 + ``` + or for 32 bit + ``` + make release-static-win32 + ``` +10. Build as a shared library in ./build/: +```cd $MONERO_CPP && ./bin/build_libmonero_cpp_dll.sh``` + ## Related projects * [monero-java](https://github.com/monero-ecosystem/monero-java) @@ -223,4 +259,4 @@ If this library brings you value, please consider donating.

46FR1GKVqFNQnDiFkH7AuzbUBrGQwz2VdaXTDD4jcjRE8YkkoTYTmZ2Vohsz9gLSqkj5EM6ai9Q7sBoX4FPPYJdGKQQXPVz
-