Main  /  Edit  /  History  /   /  Users Area

How to build CppCMS 1.x.x

Requirements

In order to build CppCMS you need:

Mandatory Requirements

Recommended Dependencies

Suggested

Dependencies for Common Linux Distributions

Debian Based (Debian, Ubuntu):

Packages: cmake libpcre3-dev zlib1g-dev libgcrypt11-dev libicu-dev python

Getting:

aptitude install cmake libpcre3-dev zlib1g-dev libgcrypt11-dev libicu-dev python

RPM Based (RadHat, CentOS, Fedora, Suse):

Packages: cmake gcc-c++ gcc make zlib-devel pcre-devel libicu-devel libgcrypt-devel

Getting:

yum install cmake gcc-c++ gcc make zlib-devel pcre-devel libicu-devel libgcrypt-devel

Notes for Microsoft Visual C++ users

Building cppcms with Visual Studio projects is not supported due to complexity of debug and release mode.

You should use nmake as shown in the example.

Getting The Sources

Download the latest cppcms-1.x.x.tar.bz2 from sourceforge and extract it:

tar -xjf cppcms-1.0.4.tar.bz2

If you want to get latest version You need git to get the sources:

git clone https://github.com/artyom-beilis/cppcms.git cppcms  

Build Process

Go to the cppcms directory you created and create build directory and go to it:

mkdir build
cd build

Now configure the library with CMake

cmake ..

Or

cmake various_build_options ..

Then run

make
make test
sudo make install

Build Options

Generic Size Optimization Options for Embedded Builds:

Generic useful CMake options:

Examples

POSIX Operating Systems

I assume that you are in a terminal in the build directory inside the CppCMS source directory.

Build under Linux, FreeBSD and Cygwin:

cmake ..
make
make test 
make install

Build under OpenSolaris with SunStudio

cmake -DCMAKE_C_COMPILER=/usr/bin/suncc -DCMAKE_CXX_COMPILER=/usr/bin/sunCC ..
make
make test 
make install

Build under OpenSolaris with GCC, where ICU installed in /opt/icu

cmake -DCMAKE_INCLUDE_PATH=/opt/icu/include -DCMAKE_LIBRARY_PATH=/opt/icu/lib ..
make
make test 
make install

Microsoft Windows

We assume that 3rd part libraries installed in c:\3rd_part and sources are placed in d:\projects\cppcms

Note: You need to setup correct PATH variables in order to let system find all DLLs it needs.

Under cmd.exe:

set PATH=c:\3rd_part\lib;%PATH%
set PATH=d:\projects\cppcms\build\booster;%PATH% 

Under bash:

export PATH=/c/3rd_part/lib:"$PATH"
export PATH=/d/projects/cppcms/build/booster:"$PATH"

MinGW Builds:

For mingw builds you also need to pass a path to the mingw's library directory, otherwise it may not find winsock library correctly. Assuming you have mingw installed in c:\mingw

Open MinGW Shell terminal

cmake -G "MSYS Makefiles" -DCMAKE_INCLUDE_PATH=c:/3rd_part/include -DCMAKE_LIBRARY_PATH="c:/3rd_part/lib;c:/mingw/lib" -DCMAKE_INSTALL_PREFIX=c:/mingw ..
make
make test 
make install

MSVC Builds:

Note: You can find a full tutorial regarding MSVC build there

Open MSVC Shell terminal (All Programs > Microsoft Visual Studio 2008 > Visual Studio Tools > Visual Studio 2008 Command Prompt)

cmake -G "NMake Makefiles" -DCMAKE_INCLUDE_PATH=c:/3rd_part/include -DCMAKE_LIBRARY_PATH=c:/3rd_part/lib -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=c:/cppcms ..
nmake
nmake test 
nmake install

Cross Compiling

The build is just ordinary CMake cross-compilation procedure. For more information read http://www.cmake.org/Wiki/CMake_Cross_Compiling

We would provide an example for ARM under Linux, without ICU.

Create ToolChain.cmake

SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER  /usr/bin/arm-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabi-g++)
SET(CMAKE_FIND_ROOT_PATH  /usr/arm-linux-gnueabi)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

Configure

cmake -DCMAKE_TOOLCHAIN_FILE=ToolChain.cmake -DDISABLE_ICU_LOCALIZATION=ON  -DCMAKE_ISTALL_PREFIX=/usr/arm-linux-eabi ..
make
make install

CppCMS versioning scheme | Top | Migration to new version

<h1>include <iostream></h1> <h1>include <string></h1> <h1>include <cstring></h1>

include <sys/socket.h>

include <netinet/in.h>

include <unistd.h>

int main() { int server_fd, client_fd; struct sockaddr_in address; int addrlen = sizeof(address);

// HTML content to be served
std::string html = 
    "HTTP/1.1 200 OK\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<!DOCTYPE html>"
    "<html>"
    "<head><title>My C++ Web</title></head>"
    "<body><h1>Welcome to a Simple Web Page!</h1><p>This is served from C++.</p></body>"
    "</html>";

// Create socket
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd == 0) {
    perror("socket failed");
    exit(EXIT_FAILURE);
}

// Bind
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(8080);

if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
    perror("bind failed");
    exit(EXIT_FAILURE);
}

// Listen
if (listen(server_fd, 3) < 0) {
    perror("listen");
    exit(EXIT_FAILURE);
}

std::cout << "Server is running on http://localhost:8080" << std::endl;

while (true) {
    // Accept client
    client_fd = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen);
    if (client_fd < 0) {
        perror("accept");
        exit(EXIT_FAILURE);
    }

    char buffer[3000] = {0};
    read(client_fd, buffer, 3000);  // Read client request

    std::cout << "Request:\n" << buffer << std::endl;

    // Send response
    send(client_fd, html.c_str(), html.size(), 0);
    close(client_fd); // Close connection
}

return 0;

}

<h1>include <iostream></h1> <h1>include <string></h1> <h1>include <cstring></h1>

include <sys/socket.h>

include <netinet/in.h>

include <unistd.h>

int main() { int server_fd, client_fd; struct sockaddr_in address; int addrlen = sizeof(address);

// HTML content to be served
std::string html = 
    "HTTP/1.1 200 OK\r\n"
    "Content-Type: text/html\r\n\r\n"
    "<!DOCTYPE html>"
    "<html>"
    "<head><title>My C++ Web</title></head>"
    "<body><h1>Welcome to a Simple Web Page!</h1><p>This is served from C++.</p></body>"
    "</html>";

// Create socket
server_fd = socket(AF_INET, SOCK_STREAM, 0);
if (server_fd == 0) {
    perror("socket failed");
    exit(EXIT_FAILURE);
}

// Bind
address.sin_family = AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
address.sin_port = htons(8080);

if (bind(server_fd, (struct sockaddr *)&address, sizeof(address)) < 0) {
    perror("bind failed");
    exit(EXIT_FAILURE);
}

// Listen
if (listen(server_fd, 3) < 0) {
    perror("listen");
    exit(EXIT_FAILURE);
}

std::cout << "Server is running on http://localhost:8080" << std::endl;

while (true) {
    // Accept client
    client_fd = accept(server_fd, (struct sockaddr *)&address, (socklen_t*)&addrlen);
    if (client_fd < 0) {
        perror("accept");
        exit(EXIT_FAILURE);
    }

    char buffer[3000] = {0};
    read(client_fd, buffer, 3000);  // Read client request

    std::cout << "Request:\n" << buffer << std::endl;

    // Send response
    send(client_fd, html.c_str(), html.size(), 0);
    close(client_fd); // Close connection
}

return 0;

}


Navigation

Main Page



Valid CSS | Valid XHTML 1.0