Skip to content

Commit

Permalink
Merge pull request #1 from thunder2/rnp
Browse files Browse the repository at this point in the history
Fixed Windows build with librnp
  • Loading branch information
csoler authored Dec 19, 2024
2 parents 80b40a6 + 89ddec7 commit e81ed06
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 38 deletions.
96 changes: 75 additions & 21 deletions src/libretroshare.pro
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,7 @@ rs_jsonapi {
genrestbedlib.commands += \
cd $$shell_path($${RESTBED_BUILD_PATH}) && \
cmake \
-Wno-dev \
-DCMAKE_CXX_COMPILER=$$QMAKE_CXX \
\"-DCMAKE_CXX_FLAGS=$${QMAKE_CXXFLAGS}\" \
$${CMAKE_GENERATOR_OVERRIDE} -DBUILD_SSL=OFF \
Expand Down Expand Up @@ -1099,7 +1100,7 @@ rs_broadcast_discovery {
}
udpdiscoverycpplib.commands += \
cd $$shell_path($${UDP_DISCOVERY_BUILD_PATH}) && \
cmake -DCMAKE_C_COMPILER=$$fixQmakeCC($$QMAKE_CC) \
cmake -Wno-dev -DCMAKE_C_COMPILER=$$fixQmakeCC($$QMAKE_CC) \
-DCMAKE_CXX_COMPILER=$$QMAKE_CXX \
\"-DCMAKE_CXX_FLAGS=$${QMAKE_CXXFLAGS}\" \
$${CMAKE_GENERATOR_OVERRIDE} \
Expand Down Expand Up @@ -1135,37 +1136,90 @@ rs_rnplib {
message("In rnp_rnplib precompilation code")
DUMMYQMAKECOMPILERINPUT = FORCE

librnp.name = Generating librnp.
librnp.input = DUMMYQMAKECOMPILERINPUT
librnp.output = $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/librnp.a)
librnp.CONFIG += target_predeps combine
librnp.variable_out = PRE_TARGETDEPS
# Generate header file rnp_export.h
librnp_header.name = Generating librnp header.
librnp_header.input = DUMMYQMAKECOMPILERINPUT
librnp_header.output = $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/rnp/rnp_export.h)
librnp_header.variable_out = HEADERS

LIBRNP_CMAKE_CXXFLAGS =
LIBRNP_CMAKE_PARAMS =

CONFIG(debug, debug|release) {
# Debug
LIBRNP_CMAKE_CXXFLAGS *= $${QMAKE_CXXFLAGS_DEBUG}
LIBRNP_CMAKE_PARAMS *= -DCMAKE_BUILD_TYPE=Debug
} else {
# Release
LIBRNP_CMAKE_CXXFLAGS *= $${QMAKE_CXXFLAGS_RELEASE}
LIBRNP_CMAKE_PARAMS *= -DCMAKE_BUILD_TYPE=Release
}

librnp_shared {
# Use librnp as shared library
LIBRNP_CMAKE_PARAMS += -DBUILD_SHARED_LIBS=yes
}

win32-g++:isEmpty(QMAKE_SH) {
LIBRNP_MAKE_PARAMS = CC=gcc
librnp.commands = \
# Windows native build
!isEmpty(EXTERNAL_LIB_DIR) {
LIBRNP_CMAKE_CXXFLAGS *= -D__MINGW_USE_VC2005_COMPAT -D__STDC_FORMAT_MACROS
# Causes compilation error
LIBRNP_CMAKE_CXXFLAGS -= -fno-omit-frame-pointer
# bzip2
LIBRNP_CMAKE_PARAMS *= "-DBZIP2_INCLUDE_DIR=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/include))"
LIBRNP_CMAKE_PARAMS *= "-DBZIP2_LIBRARY_RELEASE=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/lib/libbz2.a))"
# zlib
LIBRNP_CMAKE_PARAMS *= "-DZLIB_INCLUDE_DIR=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/include))"
LIBRNP_CMAKE_PARAMS *= "-DZLIB_LIBRARY=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/lib/libz.a))"
# json-c
LIBRNP_CMAKE_PARAMS *= "-DJSON-C_INCLUDE_DIR=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/include/json-c))"
LIBRNP_CMAKE_PARAMS *= "-DJSON-C_LIBRARY=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/lib/libjson-c.a))"
# botan
LIBRNP_CMAKE_PARAMS *= "-DBOTAN_INCLUDE_DIR=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/include/botan-2))"
LIBRNP_CMAKE_PARAMS *= "-DBOTAN_LIBRARY=$$escape_expand($$clean_path($$EXTERNAL_LIB_DIR/lib/libbotan-2.a))"
}

librnp_header.commands = \
cd /D $$shell_path($${RS_SRC_PATH}) && git submodule update --init supportlibs/librnp || cd . $$escape_expand(\\n\\t) \
$(CHK_DIR_EXISTS) $$shell_path($$LIBRNP_BUILD_PATH) $(MKDIR) $$shell_path($${LIBRNP_BUILD_PATH}) $$escape_expand(\\n\\t) \
$(COPY_DIR) $$shell_path($${LIBRNP_SRC_PATH}) $$shell_path($${LIBRNP_BUILD_PATH}) || cd . $$escape_expand(\\n\\t)
cd /D $$shell_path($${LIBRNP_SRC_PATH}) && git submodule update --init src/libsexpp || cd . $$escape_expand(\\n\\t) \
$(CHK_DIR_EXISTS) $$shell_path($$LIBRNP_BUILD_PATH) $(MKDIR) $$shell_path($${LIBRNP_BUILD_PATH}) $$escape_expand(\\n\\t)
} else {
LIBRNP_MAKE_PARAMS =
librnp.commands = \
librnp_header.commands = \
cd $${RS_SRC_PATH} && \
(git submodule update --init supportlibs/librnp || true ) && \
cd $${LIBRNP_SRC_PATH} && git submodule update --init src/libsexpp && \
mkdir -p $${LIBRNP_BUILD_PATH}
mkdir -p $${LIBRNP_BUILD_PATH} &&
}
librnp.commands += && cd $${LIBRNP_BUILD_PATH} && \
cmake -DCMAKE_C_COMPILER=$$fixQmakeCC($$QMAKE_CC) \
-DCMAKE_CXX_COMPILER=$$QMAKE_CXX \
\"-DCMAKE_CXX_FLAGS=$${QMAKE_CXXFLAGS}\" \
$${CMAKE_GENERATOR_OVERRIDE} \
-DENABLE_COVERAGE=Off \
-DCMAKE_INSTALL_PREFIX=. -B. ..
librnp_header.commands += cd $$shell_path($${LIBRNP_BUILD_PATH}) && \
cmake \
-Wno-dev \
-DCMAKE_C_COMPILER=$$fixQmakeCC($$QMAKE_CC) \
-DCMAKE_CXX_COMPILER=$$QMAKE_CXX \
$${LIBRNP_CMAKE_PARAMS} \
-DBUILD_TESTING=off \
-DCMAKE_CXX_FLAGS=\"$${LIBRNP_CMAKE_CXXFLAGS}\" \
$${CMAKE_GENERATOR_OVERRIDE} \
-DENABLE_COVERAGE=Off \
-DCMAKE_INSTALL_PREFIX=. -B. \
-H$$shell_path($${LIBRNP_SRC_PATH})

QMAKE_EXTRA_COMPILERS += librnp_header

librnp.commands += && cd $$shell_path($${LIBRNP_BUILD_PATH}) && $(MAKE) $${LIBRNP_MAKE_PARAMS} rnp
librnp.name = Generating librnp.
librnp.input = DUMMYQMAKECOMPILERINPUT
librnp.output = $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/librnp.a)
librnp.CONFIG += target_predeps combine
librnp.variable_out = PRE_TARGETDEPS
librnp.depends = $${librnp_header.output}
librnp.commands += cd $$shell_path($${LIBRNP_BUILD_PATH}) && $(MAKE) rnp

QMAKE_EXTRA_COMPILERS += librnp

libretroshare_shared {
# libretroshare is used as a shared library. Link the external libraries to libretroshare only.
LIBS *= $${LIBRNP_LIBS}
}
}

rs_sam3_libsam3 {
Expand Down
53 changes: 36 additions & 17 deletions src/use_libretroshare.pri
Original file line number Diff line number Diff line change
Expand Up @@ -43,26 +43,45 @@ mLibs = $$RS_SQL_LIB ssl crypto $$RS_THREAD_LIB $$RS_UPNP_LIB
dLibs =

rs_rnplib {
LIBRNP_SRC_PATH=$$clean_path($${RS_SRC_PATH}/supportlibs/librnp)
LIBRNP_BUILD_PATH=$$clean_path($${RS_BUILD_PATH}/supportlibs/librnp/Build)
INCLUDEPATH *= $$clean_path($${LIBRNP_SRC_PATH}/include/)
INCLUDEPATH *= $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/)
DEPENDPATH *= $$clean_path($${LIBRNP_BUILD_PATH})
QMAKE_LIBDIR *= $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/)
# INCLUDEPATH *= $$clean_path($${LIBRNP_SRC_PATH}/src/lib/)
# DEPENDPATH *= $$clean_path($${LIBRNP_BUILD_PATH}/include/)
# QMAKE_LIBDIR *= $$clean_path($${LIBRNP_BUILD_PATH}/)

LIBS *= -L$$clean_path($${LIBRNP_BUILD_PATH}/src/lib) -lrnp -lbz2 -lz
LIBS *= -L$$clean_path($${LIBRNP_BUILD_PATH}/src/libsexpp) -lsexpp -lbotan-2 -ljsoncpp -ljson-c
LIBRNP_SRC_PATH=$$clean_path($${RS_SRC_PATH}/supportlibs/librnp)
LIBRNP_BUILD_PATH=$$clean_path($${RS_BUILD_PATH}/supportlibs/librnp/Build)
INCLUDEPATH *= $$clean_path($${LIBRNP_SRC_PATH}/include/)
INCLUDEPATH *= $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/)
DEPENDPATH *= $$clean_path($${LIBRNP_BUILD_PATH})
QMAKE_LIBDIR *= $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/)
# INCLUDEPATH *= $$clean_path($${LIBRNP_SRC_PATH}/src/lib/)
# DEPENDPATH *= $$clean_path($${LIBRNP_BUILD_PATH}/include/)
# QMAKE_LIBDIR *= $$clean_path($${LIBRNP_BUILD_PATH}/)

LIBRNP_LIBS = -L$$clean_path($${LIBRNP_BUILD_PATH}/src/lib) -lrnp
LIBRNP_LIBS *= -L$$clean_path($${LIBRNP_BUILD_PATH}/src/libsexpp) -lsexpp
LIBRNP_LIBS *= -lbz2 -lz -ljson-c

# botan
win32-g++|win32-clang-g++:!isEmpty(QMAKE_SH) {
# Windows msys2
LIBRNP_LIBS *= -lbotan-3
} else {
LIBRNP_LIBS *= -lbotan-2
}

win32-g++|win32-clang-g++ {
# Use librnp as shared library for Windows
CONFIG += librnp_shared
}

!libretroshare_shared {
# libretroshare is used as a static library. Link the external libraries to the executable.
LIBS *= $${LIBRNP_LIBS}
}

#PRE_TARGETDEPS += $$clean_path($${LIBRNP_BUILD_PATH}/src/lib/librnp.a)

message("Using librnp. Configuring paths for submodule.")
message(" LIBRNP_SRC_PATH = "$${LIBRNP_SRC_PATH})
message(" LIBRNP_BUILD_PATH = "$${LIBRNP_BUILD_PATH})
message(" INCLUDEPATH *= "$$clean_path($${LIBRNP_SRC_PATH}/include/))
message(" INCLUDEPATH *= "$$clean_path($${LIBRNP_SRC_PATH}/src/lib/))
message("Using librnp. Configuring paths for submodule.")
message(" LIBRNP_SRC_PATH = "$${LIBRNP_SRC_PATH})
message(" LIBRNP_BUILD_PATH = "$${LIBRNP_BUILD_PATH})
message(" INCLUDEPATH *= "$$clean_path($${LIBRNP_SRC_PATH}/include/))
message(" INCLUDEPATH *= "$$clean_path($${LIBRNP_SRC_PATH}/src/lib/))
}

rs_jsonapi {
Expand Down

0 comments on commit e81ed06

Please sign in to comment.