Skip to content

Commit

Permalink
Merge pull request #157 from ppenzin/cmake_refactor. Fix #143.
Browse files Browse the repository at this point in the history
Refactor library build configuration
  • Loading branch information
andyli committed Feb 27, 2017
2 parents 841d1ed + a322c60 commit a64e31d
Show file tree
Hide file tree
Showing 13 changed files with 841 additions and 727 deletions.
758 changes: 34 additions & 724 deletions CMakeLists.txt

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions README.md
Expand Up @@ -101,11 +101,17 @@ A number of options can be used to customize the build. They can be specified in
cmake "-Doption=value" ..
```

#### `WITH_NDLLS`
#### NDLLs

Available on all platforms. Default value: `std.ndll;zlib.ndll;mysql.ndll;mysql5.ndll;regexp.ndll;sqlite.ndll;ui.ndll;mod_neko2.ndll;mod_tora2.ndll;ssl.ndll`
Settings that allow to exclude libraries and their dependencies from the build; available on all platforms. By default all are "ON":

- WITH_REGEXP - Build Perl-compatible regex support
- WITH_UI - Build GTK-2 UI support
- WITH_SSL - Build SSL support
- WITH_MYSQL - Build MySQL support
- WITH_SQLITE - Build Sqlite support
- WITH_APACHE - Build Apach modules

It defines the ndll files to be built. You may remove ndlls from this list, such that you can avoid installing/building some dependencies.

#### `STATIC_DEPS`

Expand Down
186 changes: 186 additions & 0 deletions libs/CMakeLists.txt
@@ -1 +1,187 @@
add_subdirectory(common)
add_subdirectory(std)
add_subdirectory(zlib)
if (WITH_MYSQL)
add_subdirectory(mysql)
endif()
if (WITH_REGEXP)
add_subdirectory(regexp)
endif()
if (WITH_SQLITE)
add_subdirectory(sqlite)
endif()
if (WITH_SSL)
add_subdirectory(ssl)
endif()
if (WITH_UI)
add_subdirectory(ui)
endif()

if (WITH_APACHE)
# Locate Apache
if (STATIC_APACHE)
if (STATIC_OPENSSL)
set(OPENSSL_CONF --with-openssl=${CMAKE_BINARY_DIR}/libs/src/install-prefix)
set(OPENSSL_DEP OpenSSL)
elseif()
set(OPENSSL_CONF "")
set(OPENSSL_DEP "")
endif()
if (STATIC_APR)
set(APR_CONF --with-apr=${CMAKE_BINARY_DIR}/libs/src/install-prefix)
set(APR_DEP APR)
elseif()
set(APR_CONF "")
set(APR_DEP "")
endif()
if (STATIC_APRUTIL)
set(APRUTIL_CONF --with-apr-util=${CMAKE_BINARY_DIR}/libs/src/install-prefix)
set(APRUTIL_DEP APRutil)
elseif()
set(APRUTIL_CONF "")
set(APRUTIL_DEP "")
endif()
if (STATIC_PCRE)
set(PCRE_CONF --with-pcre=${CMAKE_BINARY_DIR}/libs/src/install-prefix)
set(PCRE_DEP PCRE)
elseif()
set(PCRE_CONF "")
set(PCRE_DEP "")
endif()
if (STATIC_ZLIB)
set(ZLIB_CONF --with-z=${CMAKE_BINARY_DIR}/libs/src/install-prefix)
set(ZLIB_DEP Zlib)
elseif()
set(ZLIB_CONF "")
set(ZLIB_DEP "")
endif()

if(WIN32)
set(APR_CONFIGS
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/libs/src/install-prefix
-Wno-dev
-DAPR_INSTALL_PRIVATE_H=ON
-DINSTALL_PDB=OFF
)
else()
set(APR_CONFIGS
CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APR &&
./configure --prefix=${CMAKE_BINARY_DIR}/libs/src/install-prefix
--enable-shared=no
--enable-static=yes
--silent
BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APR &&
make CFLAGS=-w
INSTALL_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APR &&
make install
)
endif()
ExternalProject_Add(APR
${EP_CONFIGS}
URL http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
URL_MD5 98492e965963f852ab29f9e61b2ad700
${APR_CONFIGS}
)
set_target_properties(APR PROPERTIES ${EP_PROPS})


if(WIN32)
set(APRutil_CONFIGS
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/libs/src/install-prefix
-Wno-dev
-DOPENSSL_ROOT_DIR=${CMAKE_BINARY_DIR}/libs/src/install-prefix
-DINSTALL_PDB=OFF
)
else()
set(APRutil_CONFIGS
CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APRutil &&
./configure
--prefix=${CMAKE_BINARY_DIR}/libs/src/install-prefix
--silent
${APR_CONF}
${OPENSSL_CONF}
BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APRutil &&
make CFLAGS=-w
INSTALL_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/APRutil &&
make install
)
endif()
ExternalProject_Add(APRutil
${EP_CONFIGS}
DEPENDS ${APR_DEP} ${OPENSSL_DEP}
URL http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
URL_MD5 866825c04da827c6e5f53daff5569f42
${APRutil_CONFIGS}
)
set_target_properties(APRutil PROPERTIES ${EP_PROPS})


if(WIN32)
set(Apache_CONFIGS
CMAKE_ARGS
-DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/libs/src/install-prefix
-Wno-dev
-DOPENSSL_ROOT_DIR=${CMAKE_BINARY_DIR}/libs/src/install-prefix
"-DEXTRA_COMPILE_FLAGS=/D PCRE_STATIC"
-DEXTRA_LIBS=Ws2_32
BUILD_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/Apache-build &&
${CMAKE_COMMAND} --build . --target libhttpd --config ${CMAKE_CFG_INTDIR}
INSTALL_COMMAND echo skip install
)
set(APACHE_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/libs/src/install-prefix/include
${CMAKE_BINARY_DIR}/libs/src/Apache/include
${CMAKE_BINARY_DIR}/libs/src/Apache/os/win32
${CMAKE_BINARY_DIR}/libs/src/Apache-build
)
set(APACHE_LIBRARIES
${CMAKE_BINARY_DIR}/libs/src/install-prefix/lib/libapr-1.lib
${CMAKE_BINARY_DIR}/libs/src/Apache-build/${CMAKE_CFG_INTDIR}/libhttpd.lib
)
else()
set(Apache_CONFIGS
CONFIGURE_COMMAND cd ${CMAKE_BINARY_DIR}/libs/src/Apache &&
./configure
--prefix=${CMAKE_BINARY_DIR}/libs/src/Apache-build
--silent
${APR_CONF}
${APRUTIL_CONF}
${OPENSSL_CONF}
${PCRE_CONF}
${ZLIB_CONF}
BUILD_COMMAND echo skip build
INSTALL_COMMAND echo skip install
)
set(APACHE_INCLUDE_DIRS
${CMAKE_BINARY_DIR}/libs/src/install-prefix/include/apr-1
${CMAKE_BINARY_DIR}/libs/src/Apache/include
${CMAKE_BINARY_DIR}/libs/src/Apache/os/unix
)
set(APACHE_LIBRARIES

)
endif()
ExternalProject_Add(Apache
${EP_CONFIGS}
DEPENDS ${APR_DEP} ${APRUTIL_DEP} ${OPENSSL_DEP} ${PCRE_DEP}
URL http://archive.apache.org/dist/httpd/httpd-2.4.20.tar.gz
URL_MD5 e725c268624737a163dc844e28f720d1
${Apache_CONFIGS}
)
set_target_properties(Apache PROPERTIES ${EP_PROPS})
# Download sources for fat source archive
add_dependencies(download_static_deps Apache-download)
add_dependencies(download_static_deps APR-download)
add_dependencies(download_static_deps APRutil-download)
else()
find_package(APACHE REQUIRED)
find_package(APR REQUIRED)
set(APACHE_LIBRARIES ${APR_LIBRARIES} ${APRUTIL_LIBRARIES})
set(APACHE_INCLUDE_DIRS ${APACHE_INCLUDE_DIR} ${APR_INCLUDE_DIR} ${APRUTIL_INCLUDE_DIR})
endif()

add_subdirectory(mod_neko)
add_subdirectory(mod_tora)
endif()
2 changes: 2 additions & 0 deletions libs/common/CMakeLists.txt
Expand Up @@ -3,3 +3,5 @@ configure_file (
"${CMAKE_BINARY_DIR}/osdef.h"
)

add_library(socket socket.c)
add_library(sha1 sha1.c)
42 changes: 42 additions & 0 deletions libs/mod_neko/CMakeLists.txt
@@ -0,0 +1,42 @@

######################
# mod_neko2.ndll

add_library(mod_neko2.ndll MODULE
../../vm/stats.c # FIXME
mod_neko.c
cgi.c
)

target_include_directories(mod_neko2.ndll
PRIVATE
${APACHE_INCLUDE_DIRS}
)

target_link_libraries(mod_neko2.ndll libneko ${APACHE_LIBRARIES})

# In static Apache case build dependencies first
if (STATIC_APACHE)
add_dependencies(mod_neko2.ndll Apache APR APRutil)
endif()

set_target_properties(mod_neko2.ndll
PROPERTIES
PREFIX ""
OUTPUT_NAME mod_neko2
SUFFIX .ndll
)

if(APPLE)
set_target_properties(mod_neko2.ndll
PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup ${LINK_FLAGS}"
)
endif(APPLE)

install (
TARGETS mod_neko2.ndll
DESTINATION ${DEST_NDLL}
)

install(SCRIPT ${NEKO_FLATTEN_SCRIPT})
50 changes: 50 additions & 0 deletions libs/mod_tora/CMakeLists.txt
@@ -0,0 +1,50 @@

######################
# mod_tora2.ndll

add_library(mod_tora2.ndll MODULE
protocol.c
mod_tora.c
)

add_dependencies(mod_tora2.ndll
mod_neko2.ndll
socket
)

target_include_directories(mod_tora2.ndll
PRIVATE
${APACHE_INCLUDE_DIRS}
)

target_link_libraries(mod_tora2.ndll
socket
${APACHE_LIBRARIES}
)

if (WIN32)
target_link_libraries(mod_tora2.ndll ws2_32)
endif()

set_target_properties(mod_tora2.ndll
PROPERTIES
PREFIX ""
OUTPUT_NAME mod_tora2
SUFFIX .ndll
)

#######################

if(APPLE)
set_target_properties(mod_tora2.ndll
PROPERTIES
LINK_FLAGS "-undefined dynamic_lookup ${LINK_FLAGS}"
)
endif(APPLE)

install (
TARGETS mod_tora2.ndll
DESTINATION ${DEST_NDLL}
)

install(SCRIPT ${NEKO_FLATTEN_SCRIPT})

0 comments on commit a64e31d

Please sign in to comment.