|
| 1 | +cmake_minimum_required(VERSION 3.16) |
| 2 | + |
| 3 | +project(clienthttp) |
| 4 | + |
| 5 | +# Set default architecture if not specified |
| 6 | +if(NOT DEFINED TARGET_ARCH) |
| 7 | + set(TARGET_ARCH "x64") |
| 8 | +endif() |
| 9 | + |
| 10 | +# Set architecture-specific flags |
| 11 | +if(${TARGET_ARCH} STREQUAL "x86") |
| 12 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32") |
| 13 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m32") |
| 14 | +elseif(${TARGET_ARCH} STREQUAL "x64") |
| 15 | + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m64") |
| 16 | + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64") |
| 17 | +else() |
| 18 | + message(FATAL_ERROR "Unsupported architecture: ${TARGET_ARCH}") |
| 19 | +endif() |
| 20 | + |
| 21 | +# Enable new DTAGs to use RUNPATH instead of RPATH |
| 22 | +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--enable-new-dtags") |
| 23 | + |
| 24 | +# Set the build RUNPATH (used during runtime time) |
| 25 | +set(CMAKE_BUILD_RPATH "$ORIGIN;$ORIGIN/lib") |
| 26 | + |
| 27 | +# Set the build type to Release |
| 28 | +set(CMAKE_BUILD_TYPE "Release") |
| 29 | + |
| 30 | +# Set source and header file directories |
| 31 | +set(SOURCE_DIR src) |
| 32 | +set(HEADER_DIR include) |
| 33 | + |
| 34 | +# Add your source files |
| 35 | +set(SOURCES |
| 36 | + ${SOURCE_DIR}/main.cpp |
| 37 | + ${SOURCE_DIR}/base64.cpp |
| 38 | + ${SOURCE_DIR}/http.cpp |
| 39 | + ${SOURCE_DIR}/json.cpp |
| 40 | + ${SOURCE_DIR}/utilities.cpp |
| 41 | + ${SOURCE_DIR}/operations.cpp |
| 42 | +) |
| 43 | + |
| 44 | +# Optionally, add headers for IDEs or reference |
| 45 | +set(HEADERS |
| 46 | + ${HEADER_DIR}/base64.h |
| 47 | + ${HEADER_DIR}/http.h |
| 48 | + ${HEADER_DIR}/json.h |
| 49 | + ${HEADER_DIR}/utilities.h |
| 50 | + ${HEADER_DIR}/operations.h |
| 51 | +) |
| 52 | + |
| 53 | +# Create the executable (using only source files) |
| 54 | +add_executable(clienthttp ${SOURCES}) |
| 55 | + |
| 56 | +# Set the C++17 standard |
| 57 | +target_compile_features(clienthttp PRIVATE cxx_std_17) |
| 58 | + |
| 59 | +# Include the header directory |
| 60 | +target_include_directories(clienthttp PRIVATE ${HEADER_DIR}) |
| 61 | + |
| 62 | +# Link the curl library |
| 63 | +find_package(CURL REQUIRED) |
| 64 | +target_link_libraries(clienthttp PRIVATE CURL::libcurl) |
| 65 | + |
| 66 | +# Link the pthread library |
| 67 | +find_package(Threads REQUIRED) |
| 68 | +target_link_libraries(clienthttp PRIVATE Threads::Threads) |
| 69 | + |
| 70 | +# Link against the stdc++fs library |
| 71 | +target_link_libraries(clienthttp PRIVATE stdc++fs) |
| 72 | + |
| 73 | +# Set linker flags to disable symbol generation |
| 74 | +set_target_properties(clienthttp PROPERTIES LINK_FLAGS_RELEASE "-s") |
| 75 | + |
| 76 | +# Set compiler flags for size optimization |
| 77 | +target_compile_options(clienthttp PRIVATE -Os) |
0 commit comments