Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
it_bear committed Aug 18, 2020
1 parent 516edf6 commit 39b61cd
Show file tree
Hide file tree
Showing 22 changed files with 148 additions and 1,333 deletions.
11 changes: 0 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@
!*.ASM
!*.qml
!*.qmlproject
!*.rst
!*.md
!Makefile

#
!*.jar
Expand Down Expand Up @@ -86,7 +83,6 @@

# Don't ignore scripts
!*.sh
!*.bat

# Don't ignore ssl
!*.pem
Expand Down Expand Up @@ -146,13 +142,6 @@

moc_*.cpp

# Ignore docs build
**/docs/build/*

# Ignore JetBrain IDEs
**/.idea/

# Ignore CMake files
CMakeCache.txt
/CMakeFiles/

235 changes: 107 additions & 128 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,145 +1,124 @@
cmake_minimum_required(VERSION 3.16)

project(UnoSemuxLightCoreWasm
VERSION 0.1.0
DESCRIPTION "C++ common utilities and types library"
LANGUAGES CXX)

set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_BUILD_PARALLEL_LEVEL 3)

set(CMAKE_SYSTEM_NAME Emscripten)
set(CMAKE_SYSTEM_PROCESSOR wasm32)
set(CMAKE_BUILD_TYPE Release)

set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten)
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake)
set(CMAKE_CXX_COMPILER em++)
set(CMAKE_C_COMPILER emcc)
set(CMAKE_CXX_STANDARD 20)
set(PROJECT_NAME UnoSemuxLightCoreWasm)
set(PROJECT_VERSION 0.1.1)
set(PROJECT_DESCRIPTION "UnoSemuxLightCoreWasm")
set(PROJECT_NAME_DEFINE UNOSEMUXLIGHTCOREWASM_LIBRARY)

#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_BUILD_PARALLEL_LEVEL 1)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_C_FLAGS_RELEASE" FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE)
set(CMAKE_MODULE_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE)
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_SHARED_LINKER_FLAGS_RELEASE" FORCE)
set(CMAKE_CXX_FLAGS_RELEASE "" CACHE STRING "Uno-labs-overridden CMAKE_CXX_FLAGS_RELEASE" FORCE)

string(JOIN " " COMPILE_FLAGS
-std=gnu++20
-O3

-s WASM=1
-s ALLOW_MEMORY_GROWTH=1
-s DISABLE_EXCEPTION_CATCHING=0

-fexceptions
-fvisibility=hidden
-fvisibility-inlines-hidden
-ffunction-sections
-fdata-sections
-fstrict-aliasing
-fstack-clash-protection

-Wall
-Wextra
-Wdouble-promotion
-Wswitch-default
-Wswitch-enum
-Wuninitialized
-Wstrict-aliasing
-Wfloat-equal
-Wshadow
-Wplacement-new
-Wcast-align
-Wconversion
-Wlogical-op
-Wduplicated-cond
-Wduplicated-branches
-Wrestrict
-Wnull-dereference
-Wno-terminate
-Wno-unknown-warning-option
-Wno-unused-command-line-argument
-Wno-comment
# Find all *.cpp and *.hpp files in project
file (GLOB_RECURSE SOURCES *.cpp)
file (GLOB_RECURSE INCLUDES *.hpp)

if (BUILD_RELEASE_WASM32)
set(NAME_OS Browser)
set(NAME_ARC wasm32)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_COMPILER em++)
set(CMAKE_C_COMPILER emcc)
set(EMSCRIPTEN_ROOT $ENV{EMSDK}/upstream/emscripten)
set(CMAKE_TOOLCHAIN_FILE ${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden -fvisibility-inlines-hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections -fexceptions -fstrict-aliasing -fstack-clash-protection")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wdouble-promotion -Wswitch-default -Wswitch-enum -Wuninitialized")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-aliasing -Wfloat-equal -Wshadow -Wplacement-new -Wcast-align -Wconversion -Wlogical-op")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wduplicated-cond -Wduplicated-branches -Wrestrict -Wnull-dereference -Wno-terminate")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wno-unused-command-line-argument -Wno-comment")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -s ALLOW_MEMORY_GROWTH=1 -s WASM=1 -s DISABLE_EXCEPTION_CATCHING=0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-gnu-string-literal-operator-template")
project(${PROJECT_NAME} DESCRIPTION ${PROJECT_DESCRIPTION} LANGUAGES CXX)
add_executable(${PROJECT_NAME} ${SOURCES})
string(JOIN " " LINK_FLAGS
-s WASM=1
-s DISABLE_EXCEPTION_CATCHING=0
-s ERROR_ON_UNDEFINED_SYMBOLS=1
-s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"]
-s ALLOW_MEMORY_GROWTH=1
-s NO_EXIT_RUNTIME=0
-O3
-Wl
--gc-sections
--bind
)

string(JOIN " " LINK_FLAGS
-s WASM=1
-s DISABLE_EXCEPTION_CATCHING=0
-s FULL_ES2=1
-s ERROR_ON_UNDEFINED_SYMBOLS=1
-s EXTRA_EXPORTED_RUNTIME_METHODS=["UTF16ToString","stringToUTF16"]
-s ALLOW_MEMORY_GROWTH=1
-s NO_EXIT_RUNTIME=0

-O3
-Wl

--gc-sections
--bind
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS})
target_link_libraries(${PROJECT_NAME}
PUBLIC
GpCore2
utf8proc
sodium
GpCryptoCore
UnoSemuxLightCore
)

# Find all *.cpp files in project
file (GLOB_RECURSE SOURCES *.cpp)

add_executable(${PROJECT_NAME} ${SOURCES})

target_compile_definitions(${PROJECT_NAME} PRIVATE
UNOSEMUXLIGHTCOREWASM_LIBRARY
HAVE_NETINET_IN_H
_GLIBCXX_USE_NANOSLEEP
__EMSCRIPTEN__
RELEASE_BUILD
NDEBUG
else()
message(FATAL_ERROR "Unknown build type, please set -DBUILD_RELEASE_WASM32=ON")
endif()

string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)

target_compile_definitions(${PROJECT_NAME}
PRIVATE
${BUILD_TYPE}_BUILD
${PROJECT_NAME_DEFINE}
HAVE_NETINET_IN_H
_GLIBCXX_USE_NANOSLEEP
)

set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS})
set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS ${LINK_FLAGS})

set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../.." CACHE PATH "..." FORCE)
set(TARGET_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin")
set(TARGET_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib")
#------------------------ FILES LOCATIONS ---------------------
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/../.." CACHE PATH "..." FORCE)
set(TARGET_LIB_DIR "${CMAKE_INSTALL_PREFIX}/bin")
set(TARGET_EXT_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/inc")

set(CMAKE_BINARY_DIR ${TARGET_BIN_DIR})
set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
if (NOT EXISTS "${TARGET_EXT_INCLUDE_DIR}")
file(MAKE_DIRECTORY "${TARGET_EXT_INCLUDE_DIR}")
endif()

set(GPCORE2 GpCore2)
set(UTF8PROC utf8proc)
set(LIBSODIUM sodium)
set(GPCRYPTOCORE GpCryptoCore)
set(SEMUXLIGHTCORE UnoSemuxLightCore)
set(SP _)
set(OUT_BIN_DIR "${TARGET_LIB_DIR}/${CMAKE_BUILD_TYPE}${SP}${NAME_OS}${SP}${NAME_ARC}")
set(LIBRARY_OUTPUT_PATH ${OUT_BIN_DIR})

#------------------------ LIBS ---------------------
target_include_directories(${PROJECT_NAME}
PRIVATE
"${TARGET_EXT_INCLUDE_DIR}"
"${TARGET_EXT_INCLUDE_DIR}/${GPCORE2}"
"${TARGET_EXT_INCLUDE_DIR}/${UTF8PROC}"
"${TARGET_EXT_INCLUDE_DIR}/${LIBSODIUM}"
"${TARGET_EXT_INCLUDE_DIR}/${GPCRYPTOCORE}"
"${TARGET_EXT_INCLUDE_DIR}/${SEMUXLIGHTCORE}"
PRIVATE
"${TARGET_EXT_INCLUDE_DIR}"
)

target_link_directories(${PROJECT_NAME}
PUBLIC ${TARGET_LIB_DIR}
)
set_property(TARGET ${PROJECT_NAME} PROPERTY VERSION ${PROJECT_VERSION})
set_property(TARGET ${PROJECT_NAME} PROPERTY SOVERSION ${PROJECT_VERSION_MAJOR})
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERFACE_${PROJECT_NAME}_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})

set_target_properties(${PROJECT_NAME}
PROPERTIES
OUTPUT_NAME ${PROJECT_NAME}
SUFFIX ".js"
ARCHIVE_OUTPUT_DIRECTORY ${OUT_BIN_DIR}
LIBRARY_OUTPUT_DIRECTORY ${OUT_BIN_DIR}
RUNTIME_OUTPUT_DIRECTORY ${OUT_BIN_DIR})

message(STATUS "[${PROJECT_NAME}]: ***************** Build mode ${BUILD_TYPE} *****************")
message(STATUS "[${PROJECT_NAME}]: Target name: " ${PROJECT_NAME}${MODE_SUFFIX} " version " ${PROJECT_VERSION})
message(STATUS "[${PROJECT_NAME}]: Target arch: " ${NAME_ARC})
message(STATUS "[${PROJECT_NAME}]: Target OS: " ${NAME_OS})
message(STATUS "[${PROJECT_NAME}]: Build directory: " ${LIBRARY_OUTPUT_PATH})
message(STATUS "[${PROJECT_NAME}]: C++ standart: " ${CMAKE_CXX_STANDARD})
message(STATUS "[${PROJECT_NAME}]: GCC C compiler: " ${CMAKE_C_COMPILER})
message(STATUS "[${PROJECT_NAME}]: GCC C++ compiler: " ${CMAKE_CXX_COMPILER})
message(STATUS "[${PROJECT_NAME}]: GCC linker: " ${CMAKE_LINKER})

target_link_libraries(${PROJECT_NAME}
target_link_directories(${PROJECT_NAME}
PUBLIC
${GPCORE2}
${UTF8PROC}
${LIBSODIUM}
${GPCRYPTOCORE}
${SEMUXLIGHTCORE}
)

message(STATUS "[${PROJECT_NAME}]: Target name: " ${PROJECT_NAME})
message(STATUS "[${PROJECT_NAME}]: Target arch: " ${CMAKE_SYSTEM_PROCESSOR})
message(STATUS "[${PROJECT_NAME}]: Target OS: " ${CMAKE_SYSTEM_NAME})
message(STATUS "[${PROJECT_NAME}]: Build directory: " ${LIBRARY_OUTPUT_PATH})
message(STATUS "[${PROJECT_NAME}]: C++ standart: " ${CMAKE_CXX_STANDARD})
message(STATUS "[${PROJECT_NAME}]: GCC C compiler version: " ${CMAKE_C_COMPILER})
message(STATUS "[${PROJECT_NAME}]: GCC C++ compiler version: " ${CMAKE_CXX_COMPILER})
${LIBRARY_OUTPUT_PATH}
)

#------------------------ INSTALL ---------------------
install(DIRECTORY "${CMAKE_SOURCE_DIR}"
DESTINATION "${TARGET_EXT_INCLUDE_DIR}"
FILES_MATCHING
PATTERN "*.hpp"
PATTERN "*.h"
PATTERN "CMake*" EXCLUDE
PATTERN ".git" EXCLUDE
)
84 changes: 0 additions & 84 deletions README.md

This file was deleted.

Loading

0 comments on commit 39b61cd

Please sign in to comment.