2023-07-09 06:08:43 +03:00
|
|
|
# This file is a part of the UMSKT Project
|
|
|
|
#
|
|
|
|
# Copyleft (C) 2019-2023 UMSKT Contributors (et.al.)
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# @FileCreated by Andrew on 05/30/2023
|
|
|
|
# @Maintainer Neo
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
CMAKE_MINIMUM_REQUIRED(VERSION 3.12)
|
|
|
|
PROJECT(UMSKT)
|
2023-09-27 20:50:08 +03:00
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
SET(CMAKE_CXX_STANDARD 17)
|
2023-08-10 23:23:01 +03:00
|
|
|
SET(CMAKE_OSX_SYSROOT "macosx" CACHE PATH "macOS SDK path")
|
2023-09-27 20:50:08 +03:00
|
|
|
|
|
|
|
OPTION(BUILD_SHARED_LIBS "Build internal libraries as dynamic" OFF)
|
2023-08-10 16:59:20 +03:00
|
|
|
OPTION(UMSKT_USE_SHARED_OPENSSL "Force linking against the system-wide OpenSSL library" OFF)
|
|
|
|
OPTION(MUSL_STATIC "Enable fully static builds in a muslc environment (i.e. Alpine Linux)" OFF)
|
|
|
|
OPTION(DJGPP_WATT32 "Enable compilation and linking with DJGPP/WATT32/OpenSSL" OFF)
|
|
|
|
OPTION(MSVC_MSDOS_STUB "Specify a custom MS-DOS stub for a 32-bit MSVC compilation" OFF)
|
|
|
|
|
|
|
|
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS})
|
|
|
|
SET(UMSKT_LINK_DIRS ${UMSKT_LINK_DIRS})
|
|
|
|
|
2023-09-02 16:55:20 +03:00
|
|
|
# macOS does not support static build
|
|
|
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
SET(UMSKT_USE_SHARED_OPENSSL ON)
|
|
|
|
endif()
|
|
|
|
|
2023-09-02 20:43:03 +03:00
|
|
|
# neither does dos idk i'm trying random stuff
|
2023-09-02 20:44:35 +03:00
|
|
|
if (DJGPP_WATT32)
|
2023-09-02 20:43:03 +03:00
|
|
|
SET(UMSKT_USE_SHARED_OPENSSL ON)
|
|
|
|
endif()
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
IF(UMSKT_USE_SHARED_OPENSSL)
|
|
|
|
SET(OPENSSL_USE_STATIC_LIBS FALSE)
|
|
|
|
SET(OPENSSL_MSVC_STATIC_RT FALSE)
|
2023-09-27 20:50:08 +03:00
|
|
|
MESSAGE(STATUS "[UMSKT] Requesting dynamic version of OpenSSL")
|
2023-08-10 16:59:20 +03:00
|
|
|
ELSE()
|
|
|
|
SET(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
|
|
SET(OPENSSL_MSVC_STATIC_RT TRUE)
|
2023-09-27 20:50:08 +03:00
|
|
|
MESSAGE(STATUS "[UMSKT] Requesting static version of OpenSSL")
|
2023-08-10 16:59:20 +03:00
|
|
|
ENDIF()
|
2023-07-25 09:53:42 +03:00
|
|
|
|
2023-09-02 16:55:20 +03:00
|
|
|
|
2023-09-02 16:20:54 +03:00
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
IF(DJGPP_WATT32)
|
|
|
|
SET(CMAKE_SYSTEM_NAME MSDOS)
|
2023-08-10 23:54:33 +03:00
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
|
|
|
SET(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
|
2023-08-10 16:59:20 +03:00
|
|
|
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} ${DJGPP_WATT32})
|
|
|
|
SET(UMSKT_LINK_DIRS ${UMSKT_LINK_DIRS} ${WATT_ROOT}/lib)
|
|
|
|
ENDIF()
|
|
|
|
|
2023-09-02 16:44:57 +03:00
|
|
|
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
|
|
|
SET(BUILD_SHARED_LIBS ON)
|
|
|
|
MESSAGE(STATUS "[UMSKT] macOS has no static library - Shared library forced on")
|
|
|
|
endif()
|
2023-07-25 09:53:42 +03:00
|
|
|
|
2023-08-10 16:49:04 +03:00
|
|
|
# if we're compiling with MSVC, respect the DEBUG compile option
|
2023-08-10 16:59:20 +03:00
|
|
|
IF(MSVC)
|
|
|
|
SET(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
|
|
|
IF(NOT BUILD_SHARED_LIBS)
|
|
|
|
SET(CMAKE_CXX_FLAGS_RELEASE "/MT")
|
|
|
|
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd")
|
|
|
|
ELSE()
|
|
|
|
SET(CMAKE_CXX_FLAGS_RELEASE "/MD")
|
|
|
|
SET(CMAKE_CXX_FLAGS_DEBUG "/MDd")
|
|
|
|
ENDIF()
|
|
|
|
SET(CMAKE_EXE_LINKER_FLAGS "/INCREMENTAL:NO /NODEFAULTLIB:MSVCRT")
|
|
|
|
SET(CMAKE_ENABLE_EXPORTS ON)
|
|
|
|
SET(UMSKT_EXE_WINDOWS_EXTRA src/windows/umskt.rc)
|
|
|
|
SET(UMSKT_EXE_WINDOWS_DLL src/windows/dllmain.cpp)
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(MUSL_STATIC)
|
|
|
|
MESSAGE(STATUS "[UMSKT] Performing a fully static build using muslc")
|
2023-09-27 20:50:08 +03:00
|
|
|
SET(BUILD_SHARED_LIBS OFF)
|
|
|
|
SET(OPENSSL_USE_STATIC_LIBS TRUE)
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
SET(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
|
|
|
|
SET(CMAKE_SHARED_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
|
|
|
|
SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
|
|
|
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++")
|
|
|
|
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
|
|
|
|
ENDIF()
|
|
|
|
|
2023-09-27 20:50:08 +03:00
|
|
|
# find the system installed OpenSSL development library
|
|
|
|
FIND_PACKAGE(OpenSSL REQUIRED)
|
|
|
|
IF(NOT OPENSSL_FOUND)
|
|
|
|
MESSAGE(SEND_ERROR "OpenSSL Development Libraries Not Found")
|
|
|
|
MESSAGE(SEND_ERROR "Please consult your package manager of choice to install the prerequisite")
|
|
|
|
MESSAGE(SEND_ERROR "The package name is commonly called libssl-dev or openssl-dev depending on distribution")
|
|
|
|
MESSAGE(FATAL_ERROR "Can not continue without OpenSSL")
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(NOT MUSL_STATIC)
|
|
|
|
# if we found shared libraries - do the following:
|
|
|
|
IF (OPENSSL_USE_STATIC_LIBS)
|
|
|
|
MESSAGE(STATUS "[UMSKT] requested static version of OpenSSL")
|
|
|
|
if (NOT UMSKT_USE_SHARED_OPENSSL)
|
|
|
|
MESSAGE(STATUS "[UMSKT] not asked for shared version of OpenSSL")
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
IF(MSVC)
|
|
|
|
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} "ws2_32.lib")
|
|
|
|
SET(UMSKT_LINK_LIBS ${UMSKT_LINK_LIBS} "crypt32.lib")
|
|
|
|
MESSAGE(STATUS "[UMSKT] msvc adding ws2_32.lib crypt32.lib")
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
|
|
|
STRING(REGEX MATCH "(\\.so|\\.dll|\\.dylib)$" OPENSSL_CRYPTO_SHARED "${OPENSSL_CRYPTO_LIBRARY}")
|
|
|
|
IF(OPENSSL_CRYPTO_SHARED)
|
|
|
|
MESSAGE(STATUS "[UMSKT] Detected Shared library version of OpenSSL")
|
|
|
|
ELSE()
|
|
|
|
MESSAGE(STATUS "[UMSKT] Detected Static Library version of OpenSSL")
|
|
|
|
|
|
|
|
# static libcrypto on Fedora needs -lz at link time
|
|
|
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|
|
|
FIND_PACKAGE(ZLIB REQUIRED)
|
|
|
|
IF (NOT ZLIB_FOUND)
|
|
|
|
MESSAGE(FATAL_ERROR "[UMSKT] linux static OpenSSL requires zlib")
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
# initalize cpm.CMake
|
|
|
|
INCLUDE(cmake/CPM.cmake)
|
|
|
|
|
|
|
|
# fetch cpm.CMake dependencies
|
|
|
|
# Include JSON development library
|
2023-06-01 20:55:36 +03:00
|
|
|
CPMAddPackage(
|
2023-08-10 16:59:20 +03:00
|
|
|
NAME nlohmann_json
|
|
|
|
GITHUB_REPOSITORY nlohmann/json
|
|
|
|
VERSION 3.11.2
|
2023-06-02 15:36:34 +03:00
|
|
|
)
|
2023-06-01 20:55:36 +03:00
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
# Include fmt development library
|
2023-07-09 06:08:43 +03:00
|
|
|
CPMAddPackage(
|
2023-08-10 16:59:20 +03:00
|
|
|
NAME fmt
|
|
|
|
GITHUB_REPOSITORY fmtlib/fmt
|
|
|
|
GIT_TAG 10.0.0
|
|
|
|
VERSION 10.0.0
|
2023-07-09 06:08:43 +03:00
|
|
|
)
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
# Include cmrc resource compiler
|
2023-07-09 06:08:43 +03:00
|
|
|
CPMAddPackage(
|
2023-08-10 16:59:20 +03:00
|
|
|
NAME cmrc
|
|
|
|
GITHUB_REPOSITORY vector-of-bool/cmrc
|
|
|
|
GIT_TAG 2.0.1
|
|
|
|
VERSION 2.0.1
|
2023-07-09 06:08:43 +03:00
|
|
|
)
|
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
# Include Crypto++ development library
|
|
|
|
#CPMAddPackage(
|
|
|
|
# NAME cryptopp-cmake
|
|
|
|
# GITHUB_REPOSITORY abdes/cryptopp-cmake
|
|
|
|
# GIT_TAG CRYPTOPP_8_8_0
|
|
|
|
# VERSION 8.8.0
|
|
|
|
# OPTIONS "CRYPTOPP_BUILD_TESTING OFF"
|
|
|
|
#)
|
|
|
|
|
|
|
|
#include googletest unit testing library
|
|
|
|
#CPMAddPackage(
|
|
|
|
# NAME googletest
|
|
|
|
# GITHUB_REPOSITORY google/googletest
|
|
|
|
# VERSION 1.13.0
|
|
|
|
# OPTIONS "INSTALL_GTEST OFF" "gtest_force_shared_crt"
|
|
|
|
#)
|
|
|
|
|
|
|
|
### Resource compilation
|
2023-07-09 06:08:43 +03:00
|
|
|
CMRC_ADD_RESOURCE_LIBRARY(umskt-rc ALIAS umskt::rc NAMESPACE umskt keys.json)
|
2023-06-01 18:54:11 +03:00
|
|
|
|
2023-08-10 16:59:20 +03:00
|
|
|
SET(LIBUMSKT_SRC src/libumskt/libumskt.cpp src/libumskt/pidgen3/BINK1998.cpp src/libumskt/pidgen3/BINK2002.cpp src/libumskt/pidgen3/key.cpp src/libumskt/pidgen3/util.cpp src/libumskt/confid/confid.cpp src/libumskt/pidgen2/PIDGEN2.cpp src/libumskt/debugoutput.cpp)
|
2023-07-25 09:53:42 +03:00
|
|
|
|
2023-08-10 16:49:04 +03:00
|
|
|
#### Separate Build Path for emscripten
|
2023-08-10 16:59:20 +03:00
|
|
|
IF (EMSCRIPTEN)
|
|
|
|
ADD_EXECUTABLE(umskt ${LIBUMSKT_SRC})
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${OPENSSL_INCLUDE_DIR})
|
|
|
|
TARGET_LINK_LIBRARIES(umskt -static OpenSSL::Crypto cryptopp::cryptopp fmt)
|
|
|
|
SET(CMAKE_EXECUTABLE_SUFFIX ".html")
|
|
|
|
|
|
|
|
SET_TARGET_PROPERTIES(umskt PROPERTIES COMPILE_FLAGS "-Os -sEXPORTED_RUNTIME_METHODS=ccall,cwrap")
|
|
|
|
SET_TARGET_PROPERTIES(umskt PROPERTIES LINK_FLAGS "-Os -sWASM=1 -sEXPORT_ALL=1 -sEXPORTED_RUNTIME_METHODS=ccall,cwrap --no-entry")
|
|
|
|
ELSE()
|
2023-09-27 20:50:08 +03:00
|
|
|
ADD_LIBRARY(_umskt ${LIBUMSKT_SRC} ${UMSKT_EXE_WINDOWS_EXTRA} ${UMSKT_EXE_WINDOWS_DLL})
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(_umskt PUBLIC ${OPENSSL_INCLUDE_DIR})
|
|
|
|
TARGET_LINK_DIRECTORIES(_umskt PUBLIC ${UMSKT_LINK_DIRS})
|
|
|
|
TARGET_LINK_LIBRARIES(_umskt ${OPENSSL_CRYPTO_LIBRARIES} fmt ${UMSKT_LINK_LIBS})
|
2023-08-10 16:49:04 +03:00
|
|
|
|
|
|
|
### UMSKT executable compilation
|
2023-08-10 16:59:20 +03:00
|
|
|
ADD_EXECUTABLE(umskt src/main.cpp src/cli.cpp ${UMSKT_EXE_WINDOWS_EXTRA})
|
|
|
|
TARGET_INCLUDE_DIRECTORIES(umskt PUBLIC ${OPENSSL_INCLUDE_DIR})
|
2023-09-27 20:50:08 +03:00
|
|
|
TARGET_LINK_LIBRARIES(umskt _umskt ${OPENSSL_CRYPTO_LIBRARIES} ${ZLIB_LIBRARIES} fmt nlohmann_json::nlohmann_json umskt::rc ${UMSKT_LINK_LIBS})
|
2023-08-10 16:59:20 +03:00
|
|
|
TARGET_LINK_DIRECTORIES(umskt PUBLIC ${UMSKT_LINK_DIRS})
|
|
|
|
IF(MSVC AND MSVC_MSDOS_STUB)
|
|
|
|
SET_PROPERTY(TARGET umskt APPEND PROPERTY LINK_FLAGS /STUB:${MSVC_MSDOS_STUB})
|
|
|
|
ENDIF()
|
2023-08-10 16:49:04 +03:00
|
|
|
|
2023-09-27 20:50:08 +03:00
|
|
|
IF (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
|
|
|
install(TARGETS umskt DESTINATION bin)
|
|
|
|
ENDIF()
|
|
|
|
|
2023-08-10 16:49:04 +03:00
|
|
|
### Copy Shared Libraries and dependency files
|
2023-08-10 16:59:20 +03:00
|
|
|
IF (OPENSSL_CRYPTO_SHARED)
|
|
|
|
GET_FILENAME_COMPONENT(OPENSSL_CRYPTO_LIBRARY_FILENAME ${OPENSSL_CRYPTO_LIBRARY} NAME)
|
|
|
|
CONFIGURE_FILE(${OPENSSL_CRYPTO_LIBRARY} "${CMAKE_CURRENT_BINARY_DIR}/${OPENSSL_CRYPTO_LIBRARY_FILENAME}" COPYONLY)
|
|
|
|
ENDIF()
|
|
|
|
ENDIF()
|