Closed JiahangOK closed 4 years ago
I have heard that people are using this on iOS, but I don't have a machine that I can try it on. Hopefully someone else can help out.
@fpagliughi Thanks for helping. I have a question, if I want to compile this library to run on IOS platform, should I just need to change a little on the CMakeLists.txt?
I have used the XCode generator with CMake to compile it, but from the error information, I think the generator deleted my libsockpp.a. I want to generate static library, so I set the options like this:
option(SOCKPP_BUILD_STATIC "Build static library" ON)
option(SOCKPP_BUILD_SHARED "Build shared library" OFF)
During the compiIing, I found this piece of log information, seems that my .a library was deleted.
PhaseScriptExecution CMake\ PostBuild\ Rules build/src/sockpp.build/Release-iphoneos/sockpp-objs.build/Script-D0E50D65C7B545EF9DD83FF8.sh
cd /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp
/bin/sh -c /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build/src/sockpp.build/Release-iphoneos/sockpp-objs.build/Script-D0E50D65C7B545EF9DD83FF8.sh
echo "Depend check for xcode"
Depend check for xcode
cd /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build && make -C /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build -f /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build/CMakeScripts/XCODE_DEPEND_HELPER.make OBJDIR=Objects-normal PostBuild.sockpp-objs.Release
/bin/rm -f /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build/Release-iphoneos/libsockpp.a
After that, I got error like this.
PhaseScriptExecution CMake\ PostBuild\ Rules build/sockpp.build/Release-iphoneos/install.build/Script-CAF3384184CE4ADDB4D642EE.sh
cd /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp
/bin/sh -c /Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build/sockpp.build/Release-iphoneos/install.build/Script-CAF3384184CE4ADDB4D642EE.sh
/Applications/CMake.app/Contents/bin/cmake -DBUILD_TYPE=Release -DEFFECTIVE_PLATFORM_NAME=-iphoneos -P cmake_install.cmake
-- Install configuration: "Release"
CMake Error at cmake_install.cmake:43 (file):
file INSTALL cannot find
"/Users/wujiahang/Project/EdgeTileIOS/deps/sockpp/build/Release-iphoneos/libsockpp.a":
No such file or directory.
make: *** [install_buildpart_0] Error 1
Command /bin/sh failed with exit code 2
** BUILD FAILED **
The following build commands failed:
PhaseScriptExecution CMake\ PostBuild\ Rules build/sockpp.build/Release-iphoneos/install.build/Script-CAF3384184CE4ADDB4D642EE.sh
(1 failure)
It‘s so wierd. Should I change something on CMakeLists.txt to make it useful on IOS platform?
Thanks, I have solve the problem, the library can exactly be used on IOS platform. I change the CMakeLists.txt under the sockpp directory. The issue can be closed.
## CMake required version
cmake_minimum_required(VERSION 3.5)
## project
project(sockpp VERSION "0.7.0")
## library name
set(SOCKPP sockpp)
set(SOCKPP_STATIC ${SOCKPP}-static)
# --- Build Options ---
if (WIN32)
option(SOCKPP_BUILD_STATIC "Build static library" ON)
option(SOCKPP_BUILD_SHARED "Build shared library (DLL)" OFF)
else ()
option(SOCKPP_BUILD_STATIC "Build static library" ON)
option(SOCKPP_BUILD_SHARED "Build shared library" OFF)
endif ()
option(SOCKPP_BUILD_EXAMPLES "Build example applications" OFF)
option(SOCKPP_BUILD_TESTS "Build unit tests" OFF)
option(SOCKPP_BUILD_DOCUMENTATION "Create Doxygen refe\\\\\rence documentation" OFF)
# --- C++14 build flags ---
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
# --- Generate a version header ---
#configure_file(
# ${CMAKE_CURRENT_SOURCE_DIR}/version.h.in
# generated/${SOCKPP}/version.h
# @ONLY
#)
include_directories(${sockpp_SOURCE_DIR}/include)
message("sockpp ${sockpp_SOURCE_DIR}/include")
# --- Common Library Sources, etc ---
#add_subdirectory(src)
set(SOURCES
src/acceptor.cpp
src/connector.cpp
src/datagram_socket.cpp
src/exception.cpp
src/inet_address.cpp
src/inet6_address.cpp
src/socket.cpp
src/stream_socket.cpp
src/unix/unix_address.cpp
)
# --- Header Locations ---
#target_include_directories(sockpp-objs
# PUBLIC
# $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
# $<INSTALL_INTERFACE:include>
# src
# )
set(HEADERS
include/sockpp/acceptor.h
include/sockpp/connector.h
include/sockpp/datagram_socket.h
include/sockpp/exception.h
include/sockpp/inet_address.h
include/sockpp/inet6_address.h
include/sockpp/platform.h
include/sockpp/sock_address.h
include/sockpp/socket.h
include/sockpp/stream_socket.h
include/sockpp/tcp6_acceptor.h
include/sockpp/tcp6_connector.h
include/sockpp/tcp6_socket.h
include/sockpp/tcp_acceptor.h
include/sockpp/tcp_connector.h
include/sockpp/tcp_socket.h
include/sockpp/udp6_socket.h
include/sockpp/udp_socket.h
include/sockpp/unix_acceptor.h
include/sockpp/unix_address.h
include/sockpp/unix_connector.h
include/sockpp/unix_dgram_socket.h
include/sockpp/unix_stream_socket.h
)
# --- System libraries ---
include(GNUInstallDirs)
if (WIN32)
set(LIBS_SYSTEM ws2_32)
elseif (UNIX)
set(LIBS_SYSTEM c stdc++)
endif ()
## --- create the shared library ---
if (SOCKPP_BUILD_SHARED)
message(STATUS "Creating shared library: ${SOCKPP}")
add_library(${SOCKPP} SHARED ${SOURCES} ${HEADERS})
## add dependencies to the shared library
target_link_libraries(${SOCKPP} ${LIBS_SYSTEM})
# set_target_properties(${SOCKPP} PROPERTIES
# VERSION ${PROJECT_VERSION}
# SOVERSION ${PROJECT_VERSION_MAJOR})
install(TARGETS ${SOCKPP}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif ()
# --- Create the static library ---
if (SOCKPP_BUILD_STATIC)
message(STATUS "Creating static library: ${SOCKPP_STATIC}")
add_library(${SOCKPP} STATIC ${SOURCES} ${HEADERS})
## add dependencies to the shared library
target_link_libraries(${SOCKPP} ${LIBS_SYSTEM})
# set_target_properties(${SOCKPP} PROPERTIES
# VERSION ${PROJECT_VERSION}
# SOVERSION ${PROJECT_VERSION_MAJOR})
install(TARGETS ${SOCKPP}
DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
# Let the archive use the same name as the shared library
# if (UNIX)
# set_target_properties(${SOCKPP_STATIC} PROPERTIES OUTPUT_NAME ${SOCKPP})
# endif ()
endif ()
# --- Install the library ---
#
install(DIRECTORY include/${SOCKPP}/
DESTINATION include/${SOCKPP}
FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY ${CMAKE_BINARY_DIR}/generated/${SOCKPP}/
DESTINATION include/${SOCKPP}
FILES_MATCHING PATTERN "*.h*")
# --- Documentation ---
#if(SOCKPP_BUILD_DOCUMENTATION)
# add_subdirectory(doc)
#endif()
# --- Default library for examples and unit tests ---
if (SOCKPP_BUILD_SHARED)
set(SOCKPP_LIB ${SOCKPP})
else ()
set(SOCKPP_LIB ${SOCKPP_STATIC})
endif ()
# --- Examples Applications ---
if (SOCKPP_BUILD_EXAMPLES)
add_subdirectory(examples/tcp)
add_subdirectory(examples/udp)
if (UNIX)
add_subdirectory(examples/unix)
endif ()
endif ()
# --- Unit Tests ---
if (SOCKPP_BUILD_TESTS)
add_subdirectory(tests/unit)
endif ()
Should any of this actually be put into a PR and merged into master?
I want to use CMake to compile this library for IOS, but I tried and got errors. Can I implement that? ` Creating symlinks /Applications/CMake.app/Contents/bin/cmake -E cmake_symlink_library /Users/wujiahang/Project/EdgeTileIOS/deps/build/sockpp/Release-iphoneos/libsockpp.0.7.0.dylib /Users/wujiahang/Project/EdgeTileIOS/deps/build/sockpp/Release-iphoneos/libsockpp.0.dylib /Users/wujiahang/Project/EdgeTileIOS/deps/build/sockpp/Release-iphoneos/libsockpp.dylib CMake Error: failed to create symbolic link '/Users/wujiahang/Project/EdgeTileIOS/deps/build/sockpp/Release-iphoneos/libsockpp.0.dylib': no such file or directory CMake Error: cmake_symlink_library: System Error: No such file or directory CMake Error: failed to create symbolic link '/Users/wujiahang/Project/EdgeTileIOS/deps/build/sockpp/Release-iphoneos/libsockpp.dylib': no such file or directory CMake Error: cmake_symlink_library: System Error: No such file or directory make: *** [sockpp_buildpart_0] Error 1
BUILD FAILED `