Skip to content

Commit 65fcaf6

Browse files
committed
cmake: Rework top level CMake file
- Allow enable/disable components
1 parent ae13aeb commit 65fcaf6

2 files changed

Lines changed: 233 additions & 4 deletions

File tree

‎CMakeLists.txt‎

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# POCO_STATIC
33
# POCO_UNBUNDLED
44
# POCO_NO_LOCALE
5+
#
6+
# ENABLE_{COMPONENT}
7+
# ENABLE_TESTS
58

69
project(Poco)
710

@@ -61,6 +64,23 @@ endif ()
6164
# For Debug build types, append a "d" to the library names.
6265
set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "Set debug library postfix" FORCE)
6366

67+
# Include some common macros to simpilfy the Poco CMake files
68+
include(PocoMacros)
69+
70+
# Allow enabling and disabling components
71+
option(ENABLE_XML "Enable the XML" ON)
72+
option(ENABLE_JSON "Enable the JSON" ON)
73+
option(ENABLE_MONGODB "Enable MongoDB" ON)
74+
option(ENABLE_PDF "Enable PDF" ON)
75+
option(ENABLE_UTIL "Enable Util" ON)
76+
option(ENABLE_NET "Enable Net" ON)
77+
option(ENABLE_NETSSL "Enable NetSSL" ON)
78+
option(ENABLE_CRYPTO "Enable Crypto" ON)
79+
option(ENABLE_DATA "Enable Data" ON)
80+
option(ENABLE_SEVENZIP "Enable SevenZip" ON)
81+
option(ENABLE_ZIP "Enable Zip" ON)
82+
option(ENABLE_APACHECONNECTOR "Enable ApacheConnector" ON)
83+
6484
option(ENABLE_TESTS
6585
"Set to OFF|ON (default is OFF) to control build of POCO tests & samples" OFF)
6686

@@ -96,7 +116,7 @@ else ()
96116
endif ()
97117

98118
# Set local include path
99-
include_directories( CppUnit/include Foundation/include XML/include Net/include NetSSL_OpenSSL/include Util/include Data/include Data/MySQL/include Data/SQLite/include Data/ODBC/include Zip/include Crypto/include Web/include JSON/include MongoDB/include PDF/include SevenZip/include)
119+
include_directories( CppUnit/include CppUnit/WinTestRunner/include Foundation/include XML/include Net/include NetSSL_OpenSSL/include Util/include Data/include Data/MySQL/include Data/SQLite/include Data/ODBC/include Zip/include Crypto/include Web/include JSON/include MongoDB/include PDF/include SevenZip/include)
100120

101121
include(CheckTypeSize)
102122
find_package(Cygwin)
@@ -160,29 +180,54 @@ if (ENABLE_TESTS)
160180
endif ()
161181

162182
add_subdirectory(Foundation)
183+
if(ENABLE_XML)
163184
add_subdirectory(XML)
185+
endif()
186+
if(ENABLE_JSON)
164187
add_subdirectory(JSON)
188+
endif()
189+
if(ENABLE_MONGODB)
165190
add_subdirectory(MongoDB)
191+
endif()
192+
if(ENABLE_PDF)
166193
add_subdirectory(PDF)
194+
endif()
195+
if(ENABLE_UTIL)
167196
add_subdirectory(Util)
197+
endif()
198+
if(ENABLE_NET)
168199
add_subdirectory(Net)
200+
endif()
169201

170202
# OPENSSL_SSL_LIBRARY
171203
find_package(OpenSSL)
172204
if(OPENSSL_FOUND)
173-
include_directories(${OPENSSL_INCLUDE_DIR})
205+
include_directories("${OPENSSL_INCLUDE_DIR}")
206+
if(ENABLE_NETSSL)
174207
add_subdirectory(NetSSL_OpenSSL)
208+
endif()
209+
if(ENABLE_CRYPTO)
175210
add_subdirectory(Crypto)
211+
endif()
176212
endif(OPENSSL_FOUND)
177213

214+
if(ENABLE_DATA)
178215
add_subdirectory(Data)
216+
endif()
217+
if(ENABLE_SEVENZIP)
179218
add_subdirectory(SevenZip)
219+
endif()
220+
if(ENABLE_ZIP)
180221
add_subdirectory(Zip)
222+
endif()
181223

182-
#find_package(ARP)
183-
#find_package(Apache2)
224+
find_package(APR)
225+
find_package(Apache2)
184226
if(APRUTIL_FOUND AND APACHE_FOUND)
227+
include_directories( "${APACHE_INCLUDE_DIR}" "${APRUTIL_INCLUDE_DIR}" )
228+
if(ENABLE_APACHECONNECTOR)
185229
add_subdirectory(ApacheConnector)
230+
endif()
186231
endif(APRUTIL_FOUND AND APACHE_FOUND)
187232

188233
#############################################################

‎cmake/PocoMacros.cmake‎

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
# Copyright Siemens AG, 2014
2+
# Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
3+
# and Contributors.
4+
#
5+
# SPDX-License-Identifier: BSL-1.0
6+
#
7+
# Collection of common functionality for Poco CMake
8+
9+
# Find the Microsoft mc.exe message compiler
10+
#
11+
# CMAKE_MC_COMPILER - where to find mc.exe
12+
if (WIN32)
13+
# cmake has CMAKE_RC_COMPILER, but no message compiler
14+
if ("${CMAKE_GENERATOR}" MATCHES "Visual Studio")
15+
# this path is only present for 2008+, but we currently require PATH to
16+
# be set up anyway
17+
get_filename_component(sdk_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows;CurrentInstallFolder]" REALPATH)
18+
get_filename_component(kit_dir "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot]" REALPATH)
19+
if (X64)
20+
set(sdk_bindir "${sdk_dir}/bin/x64")
21+
set(kit_bindir "${kit_dir}/bin/x64")
22+
else (X64)
23+
set(sdk_bindir "${sdk_dir}/bin")
24+
set(kit_bindir "${kit_dir}/bin/x86")
25+
endif (X64)
26+
endif ()
27+
find_program(CMAKE_MC_COMPILER mc.exe HINTS "${sdk_bindir}" "${kit_bindir}"
28+
DOC "path to message compiler")
29+
if (NOT CMAKE_MC_COMPILER)
30+
message(FATAL_ERROR "message compiler not found: required to build")
31+
endif (NOT CMAKE_MC_COMPILER)
32+
message(STATUS "Found message compiler: ${CMAKE_MC_COMPILER}")
33+
mark_as_advanced(CMAKE_MC_COMPILER)
34+
endif(WIN32)
35+
36+
#===============================================================================
37+
# Macros for Source file management
38+
#
39+
# POCO_SOURCES_PLAT - Adds a list of files to the sources of a components
40+
# Usage: POCO_SOURCES_PLAT( out name platform sources)
41+
# INPUT:
42+
# out the variable the sources are added to
43+
# name: the name of the components
44+
# platform: the platform this sources are for (ON = All, OFF = None, WIN32, UNIX ...)
45+
# sources: a list of files to add to ${out}
46+
# Example: POCO_SOURCES_PLAT( SRCS Foundation ON src/Foundation.cpp )
47+
#
48+
# POCO_SOURCES - Like POCO_SOURCES_PLAT with platform = ON (Built on all platforms)
49+
# Usage: POCO_SOURCES( out name sources)
50+
# Example: POCO_SOURCES( SRCS Foundation src/Foundation.cpp)
51+
#
52+
# POCO_SOURCES_AUTO - Like POCO_SOURCES but the name is read from the file header // Package: X
53+
# Usage: POCO_SOURCES_AUTO( out sources)
54+
# Example: POCO_SOURCES_AUTO( SRCS src/Foundation.cpp)
55+
#
56+
# POCO_SOURCES_AUTO_PLAT - Like POCO_SOURCES_PLAT but the name is read from the file header // Package: X
57+
# Usage: POCO_SOURCES_AUTO_PLAT(out platform sources)
58+
# Example: POCO_SOURCES_AUTO_PLAT( SRCS WIN32 src/Foundation.cpp)
59+
#
60+
#
61+
# POCO_HEADERS - Adds a list of files to the headers of a components
62+
# Usage: POCO_HEADERS( out name headers)
63+
# INPUT:
64+
# out the variable the headers are added to
65+
# name: the name of the components
66+
# headers: a list of files to add to HDRSt
67+
# Example: POCO_HEADERS( HDRS Foundation include/Poco/Foundation.h )
68+
#
69+
# POCO_HEADERS_AUTO - Like POCO_HEADERS but the name is read from the file header // Package: X
70+
# Usage: POCO_HEADERS_AUTO( out headers)
71+
# Example: POCO_HEADERS_AUTO( HDRS src/Foundation.cpp)
72+
#
73+
#
74+
# POCO_MESSAGES - Adds a list of files to the messages of a components
75+
# and adds the generated headers to the header list of the component.
76+
# On platforms other then Windows this does nothing
77+
# Usage: POCO_MESSAGES( out name messages)
78+
# INPUT:
79+
# out the variable the message and the resulting headers are added to
80+
# name: the name of the components
81+
# messages: a list of files to add to MSGS
82+
# Example: POCO_MESSAGES( HDRS Foundation include/Poco/Foundation.mc )
83+
#
84+
85+
86+
macro(POCO_SOURCES_PLAT out name platform)
87+
source_group("${name}\\Source Files" FILES ${ARGN})
88+
list(APPEND ${out} ${ARGN})
89+
if(NOT ${platform})
90+
set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE)
91+
endif()
92+
endmacro()
93+
94+
macro(POCO_SOURCES out name)
95+
POCO_SOURCES_PLAT( ${out} ${name} ON ${ARGN})
96+
endmacro()
97+
98+
macro(POCO_SOURCES_AUTO out)
99+
POCO_SOURCES_AUTO_PLAT( ${out} ON ${ARGN})
100+
endmacro()
101+
102+
macro(POCO_SOURCES_AUTO_PLAT out platform)
103+
foreach( f ${ARGN})
104+
105+
get_filename_component(fname ${f} NAME)
106+
107+
# Read the package name from the source file
108+
file(STRINGS ${f} package REGEX "// Package: (.*)")
109+
if(package)
110+
string(REGEX REPLACE ".*: (.*)" "\\1" name ${package})
111+
112+
# Files of the Form X_UNIX.cpp are treated as headers
113+
if(${fname} MATCHES ".*_.*\\..*")
114+
#message(STATUS "Platform: ${name} ${f} ${platform}")
115+
POCO_SOURCES_PLAT( ${out} ${name} OFF ${f})
116+
else()
117+
#message(STATUS "Source: ${name} ${f} ${platform}")
118+
POCO_SOURCES_PLAT( ${out} ${name} ${platform} ${f})
119+
endif()
120+
else()
121+
#message(STATUS "Source: Unknown ${f} ${platform}")
122+
POCO_SOURCES_PLAT( ${out} Unknown ${platform} ${f})
123+
endif()
124+
endforeach()
125+
endmacro()
126+
127+
128+
macro(POCO_HEADERS_AUTO out)
129+
foreach( f ${ARGN})
130+
131+
get_filename_component(fname ${f} NAME)
132+
133+
# Read the package name from the source file
134+
file(STRINGS ${f} package REGEX "// Package: (.*)")
135+
if(package)
136+
string(REGEX REPLACE ".*: (.*)" "\\1" name ${package})
137+
#message(STATUS "Header: ${name} ${f}")
138+
POCO_HEADERS( ${out} ${name} ${f})
139+
else()
140+
#message(STATUS "Header: Unknown ${f}")
141+
POCO_HEADERS( ${out} Unknown ${f})
142+
endif()
143+
endforeach()
144+
endmacro()
145+
146+
macro(POCO_HEADERS out name)
147+
set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE)
148+
source_group("${name}\\Header Files" FILES ${ARGN})
149+
list(APPEND ${out} ${ARGN})
150+
endmacro()
151+
152+
153+
macro(POCO_MESSAGES out name)
154+
if (WIN32)
155+
foreach(msg ${ARGN})
156+
get_filename_component(msg_name ${msg} NAME)
157+
get_filename_component(msg_path ${msg} ABSOLUTE)
158+
string(REPLACE ".mc" ".h" hdr ${msg_name})
159+
set_source_files_properties(${hdr} PROPERTIES GENERATED TRUE)
160+
add_custom_command(
161+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${hdr}
162+
DEPENDS ${msg}
163+
COMMAND ${CMAKE_MC_COMPILER}
164+
ARGS
165+
-h ${CMAKE_CURRENT_BINARY_DIR}
166+
-r ${CMAKE_CURRENT_BINARY_DIR}
167+
${msg_path}
168+
VERBATIM # recommended: p260
169+
)
170+
171+
# Add the generated file to the include directory
172+
include_directories(${CMAKE_CURRENT_BINARY_DIR})
173+
174+
# Add the generated headers to POCO_HEADERS of the component
175+
POCO_HEADERS( ${out} ${name} ${CMAKE_CURRENT_BINARY_DIR}/${hdr})
176+
177+
endforeach()
178+
179+
set_source_files_properties(${ARGN} PROPERTIES HEADER_FILE_ONLY TRUE)
180+
source_group("${name}\\Message Files" FILES ${ARGN})
181+
list(APPEND ${out} ${ARGN})
182+
183+
endif (WIN32)
184+
endmacro()

0 commit comments

Comments
 (0)