Skip to content

Commit 834491e

Browse files
committed
Improve CMake support for windows.
Added experimental support for building UWP. Added support for accessing NuGet packages. Renamed project to 'cpprest'. Removed superfluous ${LIB} prefix on all libs. Enabled MultiToolTask for android build. Added header files to the cpprest library, improving IDE support.
1 parent 5f75ec9 commit 834491e

File tree

21 files changed

+258
-154
lines changed

21 files changed

+258
-154
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,6 @@ Intermediate/
6363
**/packages/*
6464
# except build/, which is used as an MSBuild target.
6565
!**/packages/build/
66-
66+
.vs/
67+
# Ignore cmake building directories
68+
build.*/

Release/CMakeLists.txt

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
22
cmake_minimum_required(VERSION 2.6)
3-
project(casablanca)
3+
project(cpprest)
44

55
enable_testing()
66

77
set(WARNINGS)
88
set(ANDROID_STL_FLAGS)
99

1010
option(WERROR "Threat Warnings as Errors" ON)
11+
option(BUILD_TESTS "Build tests." ON)
12+
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)
1113

1214
# Platform (not compiler) specific settings
1315
if(IOS)
@@ -27,7 +29,6 @@ if(IOS)
2729

2830
set(BUILD_SHARED_LIBS OFF)
2931
set(BUILD_SAMPLES OFF)
30-
option(BUILD_TESTS "Build tests." ON)
3132
elseif(ANDROID)
3233
set(Boost_COMPILER "-clang")
3334
set(Boost_USE_STATIC_LIBS ON)
@@ -73,7 +74,6 @@ elseif(ANDROID)
7374

7475
option(BUILD_SHARED_LIBS "Build shared Libraries." OFF)
7576
set(BUILD_SAMPLES OFF)
76-
option(BUILD_TESTS "Build tests." ON)
7777
elseif(UNIX) # This includes OSX
7878
find_package(Boost 1.54 REQUIRED COMPONENTS random chrono system thread regex filesystem)
7979
find_package(Threads REQUIRED)
@@ -88,7 +88,6 @@ elseif(UNIX) # This includes OSX
8888
find_package(OpenSSL 1.0.0 REQUIRED)
8989

9090
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
91-
option(BUILD_TESTS "Build tests." ON)
9291
option(BUILD_SAMPLES "Build samples." ON)
9392
option(CASA_INSTALL_HEADERS "Install header files." ON)
9493
if(CASA_INSTALL_HEADERS)
@@ -101,9 +100,7 @@ elseif(UNIX) # This includes OSX
101100
endif()
102101
elseif(WIN32)
103102
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
104-
option(BUILD_TESTS "Build tests." ON)
105103
option(BUILD_SAMPLES "Build samples." ON)
106-
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)
107104
option(Boost_USE_STATIC_LIBS ON)
108105

109106
add_definitions(-DUNICODE -D_UNICODE)
@@ -117,11 +114,31 @@ elseif(WIN32)
117114
endif()
118115
add_definitions(${Casablanca_DEFINITIONS} -D_WINSOCK_DEPRECATED_NO_WARNINGS -DWIN32)
119116

120-
if (CPPREST_EXCLUDE_WEBSOCKETS)
121-
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
122-
else()
123-
find_package(Boost 1.55 REQUIRED COMPONENTS random system thread filesystem chrono atomic)
124-
find_package(OpenSSL 1.0 REQUIRED)
117+
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
118+
set(NUGET_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../packages")
119+
set(PACKAGE_PATHS)
120+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost.1.58.0.0/")
121+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_system-vc140.1.58.0-vs140rc/")
122+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_date_time-vc140.1.58.0-vs140rc/")
123+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_regex-vc140.1.58.0-vs140rc/")
124+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/")
125+
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8/")
126+
127+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
128+
find_library(Boost_SYSTEM_LIBRARY libboost_system-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
129+
find_library(Boost_DATE_TIME_LIBRARY libboost_date_time-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
130+
find_library(Boost_REGEX_LIBRARY libboost_regex-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
131+
set(Boost_LIBRARIES ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY})
132+
133+
find_library(OpenSSL_libeay_LIBRARY libeay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
134+
find_library(OpenSSL_ssleay_LIBRARY ssleay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
135+
find_library(ZLIB_LIBRARY zlibstaticd.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
136+
set(OPENSSL_LIBRARIES ${OpenSSL_ssleay_LIBRARY} ${OpenSSL_libeay_LIBRARY} ${ZLIB_LIBRARY})
137+
138+
set(OPENSSL_INCLUDE_DIR "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/build/native/include")
139+
endif()
140+
141+
set(Boost_INCLUDE_DIR "${NUGET_PATH}/boost.1.58.0.0/lib/native/include")
125142
endif()
126143
else()
127144
message(FATAL_ERROR "-- Unsupported Build Platform.")
@@ -160,11 +177,20 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
160177
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
161178
message("-- Setting msvc options")
162179
set(WARNINGS)
180+
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4264")
181+
add_compile_options(/bigobj)
182+
if (WINDOWS_STORE OR WINDOWS_PHONE)
183+
add_compile_options(/ZW)
184+
endif()
163185
else()
164186
message("-- Unknown compiler, success is doubtful.")
165187
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
166188
endif()
167189

190+
if (CPPREST_EXCLUDE_WEBSOCKETS)
191+
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
192+
endif()
193+
168194
# Reconfigure final output directory
169195
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
170196
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
@@ -190,9 +216,8 @@ else()
190216
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
191217
endif()
192218

193-
set(Casablanca_LIBRARY ${LIB}cpprest)
194-
set(Casablanca_LIBRARIES ${Casablanca_LIBRARY}
195-
${Boost_LIBRARIES})
219+
set(Casablanca_LIBRARY cpprest)
220+
set(Casablanca_LIBRARIES cpprest ${Boost_LIBRARIES})
196221

197222
# Everything in the project needs access to the casablanca include directories
198223
include_directories(${Casablanca_INCLUDE_DIRS})
@@ -203,16 +228,16 @@ function(add_casablanca_test NAME SOURCES_VAR)
203228
message("-- Added test library ${NAME}")
204229
if (NOT TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
205230
target_link_libraries(${NAME}
206-
${LIB}httptest_utilities
207-
${LIB}common_utilities
208-
${LIB}unittestpp
231+
httptest_utilities
232+
common_utilities
233+
unittestpp
209234
${Casablanca_LIBRARIES}
210235
${ANDROID_STL_FLAGS}
211236
)
212237
if (BUILD_SHARED_LIBS)
213238
add_test(NAME ${NAME}
214239
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
215-
COMMAND test_runner lib${NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
240+
COMMAND test_runner $<TARGET_FILE_NAME:${NAME}>
216241
)
217242
endif()
218243
endif()
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
add_executable(BingRequest bingrequest.cpp)
2-
target_link_libraries(BingRequest ${Casablanca_LIBRARIES})
1+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2+
add_executable(BingRequest bingrequest.cpp)
3+
target_link_libraries(BingRequest ${Casablanca_LIBRARIES})
4+
endif()
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
add_subdirectory(BlackJack_Server)
2-
add_subdirectory(BlackJack_Client)
1+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2+
add_subdirectory(BlackJack_Server)
3+
add_subdirectory(BlackJack_Client)
4+
else()
5+
# TODO: add BlackJack_UIClient
6+
endif()
Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
2-
add_executable(oauth1client
3-
Oauth1Client.cpp
4-
stdafx.cpp
5-
)
6-
7-
target_link_libraries(oauth1client ${Casablanca_LIBRARIES})
1+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2+
add_executable(oauth1client
3+
Oauth1Client.cpp
4+
stdafx.cpp
5+
)
6+
7+
target_link_libraries(oauth1client ${Casablanca_LIBRARIES})
8+
endif()
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2+
add_executable(oauth2client
3+
Oauth2Client.cpp
4+
stdafx.cpp
5+
)
16

2-
add_executable(oauth2client
3-
Oauth2Client.cpp
4-
stdafx.cpp
5-
)
6-
7-
target_link_libraries(oauth2client ${Casablanca_LIBRARIES})
7+
target_link_libraries(oauth2client ${Casablanca_LIBRARIES})
8+
endif()
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
add_executable(SearchFile searchfile.cpp)
2-
target_link_libraries(SearchFile ${Casablanca_LIBRARIES})
1+
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
2+
add_executable(SearchFile searchfile.cpp)
3+
target_link_libraries(SearchFile ${Casablanca_LIBRARIES})
4+
endif()

Release/src/CMakeLists.txt

Lines changed: 57 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,21 @@ if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
33
include_directories(${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
44
endif()
55

6+
add_definitions(${WARNINGS})
7+
8+
file(GLOB SOURCES_CPPREST "../include/cpprest/*.h")
9+
file(GLOB SOURCES_PPLX "../include/pplx/*.h")
10+
file(GLOB SOURCES_DETAILS "../include/cpprest/details/*.h")
11+
source_group("Header Files\\cpprest" FILES ${SOURCES_CPPREST})
12+
source_group("Header Files\\pplx" FILES ${SOURCES_PPLX})
13+
source_group("Header Files\\cpprest\\details" FILES ${SOURCES_DETAILS})
614
set(SOURCES_COMMON
15+
${SOURCES_CPPREST}
16+
${SOURCES_PPLX}
17+
${SOURCES_DETAILS}
18+
http/client/http_client.cpp
719
http/client/http_client_msg.cpp
20+
http/client/http_client_impl.h
821
http/client/x509_cert_utilities.cpp
922
http/common/http_helpers.cpp
1023
http/common/http_msg.cpp
@@ -25,7 +38,6 @@ set(SOURCES_COMMON
2538
utilities/web_utilities.cpp
2639
websockets/client/ws_msg.cpp
2740
websockets/client/ws_client.cpp
28-
websockets/client/ws_client_wspp.cpp
2941
)
3042

3143
# THE ORDER OF FILES IS VERY /VERY/ IMPORTANT
@@ -37,6 +49,9 @@ if(UNIX)
3749
http/client/http_client_asio.cpp
3850
http/listener/http_server_asio.cpp
3951
)
52+
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
53+
list(APPEND SOURCES websockets/client/ws_client_wspp.cpp)
54+
endif()
4055
if(APPLE)
4156
list(APPEND SOURCES
4257
pplx/pplxapple.cpp
@@ -55,45 +70,61 @@ if(UNIX)
5570
endif()
5671

5772
if(WERROR)
58-
set(WARNINGS "${WARNINGS} -Werror")
73+
add_compile_options(-Werror)
5974
endif()
60-
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS} -pedantic")
75+
add_compile_options(-pedantic)
6176
elseif(WIN32)
62-
set(SOURCES
63-
${SOURCES_COMMON}
64-
http/client/http_client_winhttp.cpp
65-
http/client/x509_cert_utilities_win32.cpp
66-
http/listener/http_server_httpsys.cpp
77+
set(SOURCES ${SOURCES_COMMON}
6778
pplx/pplxwin.cpp
68-
streams/fileio_win32.cpp
69-
pch/stdafx.cpp
7079
)
71-
set(EXTRALINKS
72-
bcrypt.lib
73-
crypt32.lib
74-
httpapi.lib
75-
Winhttp.lib
76-
)
77-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS}")
78-
if (${CMAKE_GENERATOR} MATCHES "Visual Studio .*")
79-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yustdafx.h /Zm200")
80-
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
80+
if (WINDOWS_PHONE OR WINDOWS_STORE)
81+
list(APPEND SOURCES
82+
http/client/http_client_winrt.cpp
83+
streams/fileio_winrt.cpp
84+
websockets/client/ws_client_winrt.cpp
85+
)
86+
else()
87+
list(APPEND SOURCES
88+
http/client/http_client_winhttp.cpp
89+
http/listener/http_server_httpsys.cpp
90+
streams/fileio_win32.cpp
91+
)
92+
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
93+
list(APPEND SOURCES websockets/client/ws_client_wspp.cpp)
94+
endif()
95+
set(EXTRALINKS
96+
bcrypt.lib
97+
crypt32.lib
98+
httpapi.lib
99+
Winhttp.lib
100+
)
81101
endif()
102+
add_compile_options(/Yustdafx.h /Zm200)
103+
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
104+
105+
if (NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio .*")
106+
set_property(SOURCE pch/stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
107+
set_property(SOURCE ${SOURCES} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
108+
endif()
109+
110+
list(APPEND SOURCES pch/stdafx.cpp pch/stdafx.h)
82111

83112
if (BUILD_SHARED_LIBS)
84113
add_definitions(-D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL)
85114
endif()
86115
endif()
87116

88-
add_library(${Casablanca_LIBRARY} ${SOURCES})
117+
add_library(cpprest ${SOURCES})
89118

90-
target_link_libraries(${Casablanca_LIBRARY}
119+
target_link_libraries(cpprest
91120
${CMAKE_THREAD_LIBS_INIT}
92121
${Boost_SYSTEM_LIBRARY}
93122
${Boost_THREAD_LIBRARY}
94123
${Boost_ATOMIC_LIBRARY}
95124
${Boost_CHRONO_LIBRARY}
96125
${Boost_RANDOM_LIBRARY}
126+
${Boost_REGEX_LIBRARY}
127+
${Boost_DATE_TIME_LIBRARY}
97128
${EXTRALINKS}
98129
${Boost_FRAMEWORK}
99130
${OPENSSL_LIBRARIES}
@@ -107,17 +138,17 @@ set (CPPREST_VERSION_MINOR 8)
107138
set (CPPREST_VERSION_REVISION 0)
108139

109140
if(WIN32)
110-
set_target_properties(${Casablanca_LIBRARY} PROPERTIES
111-
OUTPUT_NAME "${Casablanca_LIBRARY}_${CPPREST_VERSION_MAJOR}_${CPPREST_VERSION_MINOR}")
141+
set_target_properties(cpprest PROPERTIES
142+
OUTPUT_NAME "cpprest_${CPPREST_VERSION_MAJOR}_${CPPREST_VERSION_MINOR}")
112143
elseif(ANDROID)
113144
# Do not use SOVERSION on android. It is completely unsupported (and causes problems).
114145
# Perhaps revisit in the future? (NDK r9d, 8/7/14)
115146
else()
116-
set_target_properties(${Casablanca_LIBRARY} PROPERTIES
147+
set_target_properties(cpprest PROPERTIES
117148
SOVERSION ${CPPREST_VERSION_MAJOR}.${CPPREST_VERSION_MINOR})
118149

119150
install(
120-
TARGETS ${Casablanca_LIBRARY}
151+
TARGETS cpprest
121152
LIBRARY DESTINATION lib
122153
ARCHIVE DESTINATION lib
123154
)

Release/src/build/vs14.android/casablanca140.android.vcxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@
6060
<ImportGroup Label="PropertySheets" />
6161
<PropertyGroup Label="UserMacros" />
6262
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
63+
<UseMultiToolTask>true</UseMultiToolTask>
6364
</PropertyGroup>
6465
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
66+
<UseMultiToolTask>true</UseMultiToolTask>
6567
</PropertyGroup>
6668
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
6769
<ClCompile>
@@ -113,6 +115,12 @@
113115
<PropertyGroup>
114116
<TargetName>$(CppRestBaseFileName)140$(DebugFileSuffix)_android_$(CppRestSDKVersionFileSuffix)</TargetName>
115117
</PropertyGroup>
118+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
119+
<UseMultiToolTask>true</UseMultiToolTask>
120+
</PropertyGroup>
121+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
122+
<UseMultiToolTask>true</UseMultiToolTask>
123+
</PropertyGroup>
116124
<Import Project="..\common.vcxitems" Label="Shared" Condition="Exists('..\common.vcxitems')" />
117125
<Import Project="..\android.vcxitems" Label="Shared" Condition="Exists('..\android.vcxitems')" />
118126
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

0 commit comments

Comments
 (0)