#  Ham'n'Cheese
#  Copyright (C) 2023-2024 Scott Duensing <scott@kangaroopunch.com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>


cmake_minimum_required(VERSION 3.22)

project(n2n VERSION 3.1.1)

set(N2N_SOURCE
        src/aes.c
        src/auth.c
        src/cc20.c
        src/curve25519.c
        src/edge_management.c
        src/edge_utils.c
        src/header_encryption.c
        src/hexdump.c
        src/json.c
        src/management.c
        src/minilzo.c
        src/n2n.c
        src/n2n_port_mapping.c
        src/n2n_regex.c
        src/network_traffic_filter.c
        src/pearson.c
        src/random_numbers.c
        src/sn_management.c
        src/sn_selection.c
        src/sn_utils.c
        src/speck.c
        src/tf.c
        src/transform_aes.c
        src/transform_cc20.c
        src/transform_lzo.c
        src/transform_null.c
        src/transform_speck.c
        src/transform_tf.c
        src/transform_zstd.c
        src/tuntap_freebsd.c
        src/tuntap_linux.c
        src/tuntap_netbsd.c
        src/tuntap_osx.c
        src/wire.c
)

if(DEFINED WIN32)
set(WIN_IS_DUMB "lib")
endif()

set(N2N_LIBS
	n2n
	${CMAKE_SOURCE_DIR}/thirdparty/libnatpmp/build/libnatpmp.a
	${CMAKE_SOURCE_DIR}/thirdparty/miniupnp/miniupnpc/build/${WIN_IS_DUMB}libminiupnpc.a
)

if(DEFINED WIN32)
set(N2N_SOURCE
	${N2N_SOURCE}
	src/win32/edge_utils_win32.c
	src/win32/getopt1.c
	src/win32/getopt.c
	src/win32/wintap.c
)
set(N2N_LIBS
	${N2N_LIBS}
	netapi32
	ws2_32
	iphlpapi
)
endif()

include_directories(
	include
	${CMAKE_SOURCE_DIR}/thirdparty/libnatpmp/build
	${CMAKE_SOURCE_DIR}/thirdparty/miniupnp/miniupnpc/build
)

add_definitions(
	-O2
	-DNDEBUG
)

add_library(n2n ${N2N_SOURCE})

add_executable(edge src/edge.c)
target_link_libraries(edge ${N2N_LIBS})

add_executable(supernode src/supernode.c)
target_link_libraries(supernode ${N2N_LIBS})
