cmake_minimum_required(VERSION 3.2 FATAL_ERROR) set(AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME localproxy) set(AWS_TUNNEL_LOCAL_PROXY_LIB_NAME lproxy) project(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} CXX) option(BUILD_TESTS "Build tests" OFF) if(BUILD_TESTS) set(AWS_TUNNEL_LOCAL_PROXY_TEST_NAME localproxytest) project(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} CXX) endif(BUILD_TESTS) ###################################### # Section : Disable in-source builds # ###################################### if (${PROJECT_SOURCE_DIR} STREQUAL ${PROJECT_BINARY_DIR}) message(FATAL_ERROR "In-source builds not allowed. Please make a new directory (called a build directory) and run CMake from there. You may need to remove CMakeCache.txt and CMakeFiles folder.") endif () ######################################## # Section : Common Build setttings # ######################################## # Set required compiler standard to standard c++17. Disable extensions. set(CMAKE_CXX_STANDARD 17) # C++17 set(CMAKE_CXX_STANDARD_REQUIRED ON) #...is required... set(CMAKE_CXX_EXTENSIONS OFF) #...without compiler extensions like gnu++11 # Set position-independent code globally set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(CMAKE_FIND_LIBRARY_SUFFIXES ".a") set(CMAKE_EXE_LINKER_FLAGS "-static") set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) # Configure Compiler flags if (UNIX OR APPLE) set(CUSTOM_COMPILER_FLAGS "-O2 -D_FORTIFY_SOURCE=2 -fPIE -fstack-protector-strong -Wall -Werror") set(TEST_COMPILER_FLAGS "${CUSTOM_COMPILER_FLAGS} -D_AWSIOT_TUNNELING_NO_SSL") elseif (WIN32 OR MSVC) set(CUSTOM_COMPILER_FLAGS "/W4 /DYNAMICBASE /NXCOMPAT /analyze") set(TEST_COMPILER_FLAGS "${CUSTOM_COMPILER_FLAGS} /D_AWSIOT_TUNNELING_NO_SSL") add_definitions(-D_WIN32_WINNT=${WIN32_WINNT}) endif () ######################################### # Threading library needed for GCC # ######################################### find_package(Threads) ######################################### # Generate protobuf files # ######################################### set_property(GLOBAL PROPERTY PROTOBUF_USE_STATIC_LIBS ON) #this flag doesn't actually seem to work yet but it's documented set(PROTOBUF_PKG_VERSION "3.17.3" CACHE STRING "") find_package(Protobuf ${PROTOBUF_PKG_VERSION} REQUIRED) string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} Protobuf_LITE_STATIC_LIBRARY ${Protobuf_LITE_LIBRARY}) include_directories(${Protobuf_INCLUDE_DIRS}) include_directories(${CMAKE_CURRENT_BINARY_DIR}) #needed to include generated protobuf headers protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROJECT_SOURCE_DIR}/resources/Message.proto) ######################################### # OpenSSL dependency # ######################################### set(OPENSSL_USE_STATIC_LIBS TRUE) find_package(OpenSSL REQUIRED) include_directories(${OPENSSL_INCLUDE_DIR}) string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_SSL_LIBRARY ${OPENSSL_SSL_LIBRARY}) string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} OpenSSL_STATIC_CRYPTO_LIBRARY ${OPENSSL_CRYPTO_LIBRARY}) ######################################### # Test framework dependency # ######################################### #probably comment out for cross compiler as Catch2 is really just a header library if(BUILD_TESTS) find_package(Catch2 REQUIRED) endif(BUILD_TESTS) ######################################### # Boost dependencies # ######################################### set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_STATIC_RUNTIME ON) set(Boost_USE_DEBUG_RUNTIME OFF) #set_property(GLOBAL PROPERTY Boost_USE_MULTITHREADED ON) set(BOOST_PKG_VERSION "1.81.0" CACHE STRING "") find_package(Boost ${BOOST_PKG_VERSION} REQUIRED COMPONENTS system log log_setup thread program_options date_time filesystem chrono) include_directories(${Boost_INCLUDE_DIRS}) foreach(BOOST_LIB ${Boost_LIBRARIES}) string(REPLACE ${CMAKE_SHARED_LIBRARY_SUFFIX} ${CMAKE_STATIC_LIBRARY_SUFFIX} BOOST_STATIC_LIB ${BOOST_LIB}) list(APPEND Boost_STATIC_LIBRARIES ${BOOST_STATIC_LIB}) endforeach() ######################################### # Target : Build aws-tunnel-local-proxy # ######################################### file(GLOB ALL_SOURCES ${PROJECT_SOURCE_DIR}/src/*.cpp) set(UTIL_SOURCE ${PROJECT_SOURCE_DIR}/src/config/ConfigFile.cpp ${PROJECT_SOURCE_DIR}/src/Url.cpp) set(CORE_SOURCES ${PROJECT_SOURCE_DIR}/src/TcpAdapterProxy.cpp ${PROJECT_SOURCE_DIR}/src/ProxySettings.cpp ${PROJECT_SOURCE_DIR}/src/WebProxyAdapter.cpp ${PROTO_HDRS} ${PROTO_SRCS} ${PROJECT_SOURCE_DIR}/src/WebSocketStream.cpp) set(MAIN_SOURCES ${PROJECT_SOURCE_DIR}/src/main.cpp ${CORE_SOURCES} ${UTIL_SOURCE}) add_executable(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${MAIN_SOURCES}) set_target_properties(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} PROPERTIES LINK_SEARCH_END_STATIC ON) if(BUILD_TESTS) file(GLOB TEST_CODE ${PROJECT_SOURCE_DIR}/test/*.cpp) set(TEST_SOURCES ${TEST_CODE} ${CORE_SOURCES} ${UTIL_SOURCE}) add_executable(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${TEST_SOURCES}) set_target_properties(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} PROPERTIES LINK_SEARCH_END_STATIC ON) endif(BUILD_TESTS) #libatomic ensured for all platforms except OSX and WINDOWS if(NOT APPLE AND NOT MSVC AND NOT BUILD_TESTS) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} atomic) elseif(NOT APPLE AND NOT MSVC AND BUILD_TESTS) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} atomic) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} atomic) endif() include_directories(${PROJECT_SOURCE_DIR}/src) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_SSL_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Boost_STATIC_LIBRARIES}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${Protobuf_LITE_STATIC_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} ${CMAKE_DL_LIBS}) set_property(TARGET ${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) if(BUILD_TESTS) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_SSL_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${OpenSSL_STATIC_CRYPTO_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Boost_STATIC_LIBRARIES}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${Protobuf_LITE_STATIC_LIBRARY}) target_link_libraries(${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} ${CMAKE_DL_LIBS}) set_property(TARGET ${AWS_TUNNEL_LOCAL_PROXY_TEST_NAME} APPEND_STRING PROPERTY COMPILE_FLAGS ${TEST_COMPILER_FLAGS}) endif(BUILD_TESTS) install(TARGETS ${AWS_TUNNEL_LOCAL_PROXY_TARGET_NAME} DESTINATION "bin") ############################################### # Target : Build tcp_adapter_proxy static lib # ############################################### add_library(tcp_adapter_proxy STATIC ${PROJECT_SOURCE_DIR}/src/TcpAdapterProxy.cpp ${PROJECT_SOURCE_DIR}/src/ProxySettings.cpp ${PROJECT_SOURCE_DIR}/src/WebProxyAdapter.cpp ${PROJECT_SOURCE_DIR}/src/WebSocketStream.cpp ${PROJECT_SOURCE_DIR}/src/config/ConfigFile.cpp ${PROTO_SRCS} ) target_include_directories(tcp_adapter_proxy PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_CURRENT_BINARY_DIR} ${Protobuf_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} ) target_link_libraries(tcp_adapter_proxy PUBLIC ${CMAKE_THREAD_LIBS_INIT} ${OpenSSL_STATIC_SSL_LIBRARY} ${OpenSSL_STATIC_CRYPTO_LIBRARY} ${Boost_STATIC_LIBRARIES} ${Protobuf_LITE_STATIC_LIBRARY} ${CMAKE_DL_LIBS} ) set_property(TARGET tcp_adapter_proxy APPEND_STRING PROPERTY COMPILE_FLAGS ${CUSTOM_COMPILER_FLAGS}) install(TARGETS tcp_adapter_proxy DESTINATION "lib") install(FILES ${PROJECT_SOURCE_DIR}/src/TcpAdapterProxy.h ${PROJECT_SOURCE_DIR}/src/ProxySettings.h ${PROJECT_SOURCE_DIR}/src/WebProxyAdapter.h ${PROJECT_SOURCE_DIR}/src/WebSocketStream.h DESTINATION "include" )