Skip to content

(Successfully) Use CMakeLists.txt to replace the .bat batch file to compile this project. #5

@TheWangYang

Description

@TheWangYang

(Successfully) Use CMakeLists.txt to replace the .bat batch file to compile this project

  1. Thanks to the author for this warehouse, I have learned a lot. In order to facilitate you to use MinGW+Cmake to compile this project, I provide the following CMakeLists.txt file here:
project(cpp_study_notes_codebase)
cmake_minimum_required (VERSION 3.8)

# Set the C++ standard to 11
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

# Determine whether it is a windows32-bit system
if (!WIN32)
    link_libraries(pthread rt m)
else (!WIN32)
    link_libraries(ws2_32 wsock32)
endif (!WIN32)

# Equivalent to gcc -I
# Add the directory of the header files that need to be referenced for project compilation
include_directories(
    .
    ${PROJECT_SOURCE_DIR}/socket/src
    ${PROJECT_SOURCE_DIR}/base64
)

# Get all .cpp source files in the current directory and save them as DIR_SRC
AUX_SOURCE_DIRECTORY(. DIR_SRC)
AUX_SOURCE_DIRECTORY(${PROJECT_SOURCE_DIR}/socket/src SOCKET_SRC)

set(BASE64_SRC ${PROJECT_SOURCE_DIR}/base64/base64.cpp)


# Get the execution code named webserver_build_by_myself
ADD_EXECUTABLE(webserver_build_by_myself ${DIR_SRC} ${SOCKET_SRC} ${BASE64_SRC})
  1. I personally use the above CMakeLists.txt file to successfully compile and run smoothly in the following environment:
gcc (x86_64-posix-sjlj-rev0, Built by MinGW-W64 project) 8.1.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

cmake version 3.24.0-rc5
CMake suite maintained and supported by Kitware (kitware.com/cmake).

Hope this issue can be of some help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions