Skip to content

Commit

Permalink
Improve CMake support for windows.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ras0219-msft committed Apr 14, 2016
1 parent 5f75ec9 commit 834491e
Show file tree
Hide file tree
Showing 21 changed files with 258 additions and 154 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,6 @@ Intermediate/
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/

.vs/
# Ignore cmake building directories
build.*/
61 changes: 43 additions & 18 deletions Release/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
set(CMAKE_LEGACY_CYGWIN_WIN32 0)
cmake_minimum_required(VERSION 2.6)
project(casablanca)
project(cpprest)

enable_testing()

set(WARNINGS)
set(ANDROID_STL_FLAGS)

option(WERROR "Threat Warnings as Errors" ON)
option(BUILD_TESTS "Build tests." ON)
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)

# Platform (not compiler) specific settings
if(IOS)
Expand All @@ -27,7 +29,6 @@ if(IOS)

set(BUILD_SHARED_LIBS OFF)
set(BUILD_SAMPLES OFF)
option(BUILD_TESTS "Build tests." ON)
elseif(ANDROID)
set(Boost_COMPILER "-clang")
set(Boost_USE_STATIC_LIBS ON)
Expand Down Expand Up @@ -73,7 +74,6 @@ elseif(ANDROID)

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

option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
option(BUILD_TESTS "Build tests." ON)
option(BUILD_SAMPLES "Build samples." ON)
option(CASA_INSTALL_HEADERS "Install header files." ON)
if(CASA_INSTALL_HEADERS)
Expand All @@ -101,9 +100,7 @@ elseif(UNIX) # This includes OSX
endif()
elseif(WIN32)
option(BUILD_SHARED_LIBS "Build shared Libraries." ON)
option(BUILD_TESTS "Build tests." ON)
option(BUILD_SAMPLES "Build samples." ON)
option(CPPREST_EXCLUDE_WEBSOCKETS "Exclude websockets functionality." OFF)
option(Boost_USE_STATIC_LIBS ON)

add_definitions(-DUNICODE -D_UNICODE)
Expand All @@ -117,11 +114,31 @@ elseif(WIN32)
endif()
add_definitions(${Casablanca_DEFINITIONS} -D_WINSOCK_DEPRECATED_NO_WARNINGS -DWIN32)

if (CPPREST_EXCLUDE_WEBSOCKETS)
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
else()
find_package(Boost 1.55 REQUIRED COMPONENTS random system thread filesystem chrono atomic)
find_package(OpenSSL 1.0 REQUIRED)
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
set(NUGET_PATH "${CMAKE_CURRENT_SOURCE_DIR}/../packages")
set(PACKAGE_PATHS)
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost.1.58.0.0/")
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_system-vc140.1.58.0-vs140rc/")
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_date_time-vc140.1.58.0-vs140rc/")
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/boost_regex-vc140.1.58.0-vs140rc/")
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/")
list(APPEND PACKAGE_PATHS "${NUGET_PATH}/zlib.v140.windesktop.msvcstl.static.rt-dyn.1.2.8.8/")

if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
find_library(Boost_SYSTEM_LIBRARY libboost_system-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
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)
find_library(Boost_REGEX_LIBRARY libboost_regex-vc140-mt-gd-1_58.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/address-model-64/lib)
set(Boost_LIBRARIES ${Boost_REGEX_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_DATE_TIME_LIBRARY})

find_library(OpenSSL_libeay_LIBRARY libeay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
find_library(OpenSSL_ssleay_LIBRARY ssleay32.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
find_library(ZLIB_LIBRARY zlibstaticd.lib PATHS ${PACKAGE_PATHS} PATH_SUFFIXES lib/native/v140/windesktop/msvcstl/static/rt-dyn/x64/debug)
set(OPENSSL_LIBRARIES ${OpenSSL_ssleay_LIBRARY} ${OpenSSL_libeay_LIBRARY} ${ZLIB_LIBRARY})

set(OPENSSL_INCLUDE_DIR "${NUGET_PATH}/openssl.v140.windesktop.msvcstl.static.rt-dyn.x64.1.0.2.1/build/native/include")
endif()

set(Boost_INCLUDE_DIR "${NUGET_PATH}/boost.1.58.0.0/lib/native/include")
endif()
else()
message(FATAL_ERROR "-- Unsupported Build Platform.")
Expand Down Expand Up @@ -160,11 +177,20 @@ elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
message("-- Setting msvc options")
set(WARNINGS)
set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4264")
add_compile_options(/bigobj)
if (WINDOWS_STORE OR WINDOWS_PHONE)
add_compile_options(/ZW)
endif()
else()
message("-- Unknown compiler, success is doubtful.")
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
endif()

if (CPPREST_EXCLUDE_WEBSOCKETS)
add_definitions(-DCPPREST_EXCLUDE_WEBSOCKETS=1)
endif()

# Reconfigure final output directory
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/Binaries)
Expand All @@ -190,9 +216,8 @@ else()
set(Casablanca_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/include)
endif()

set(Casablanca_LIBRARY ${LIB}cpprest)
set(Casablanca_LIBRARIES ${Casablanca_LIBRARY}
${Boost_LIBRARIES})
set(Casablanca_LIBRARY cpprest)
set(Casablanca_LIBRARIES cpprest ${Boost_LIBRARIES})

# Everything in the project needs access to the casablanca include directories
include_directories(${Casablanca_INCLUDE_DIRS})
Expand All @@ -203,16 +228,16 @@ function(add_casablanca_test NAME SOURCES_VAR)
message("-- Added test library ${NAME}")
if (NOT TEST_LIBRARY_TARGET_TYPE STREQUAL "OBJECT")
target_link_libraries(${NAME}
${LIB}httptest_utilities
${LIB}common_utilities
${LIB}unittestpp
httptest_utilities
common_utilities
unittestpp
${Casablanca_LIBRARIES}
${ANDROID_STL_FLAGS}
)
if (BUILD_SHARED_LIBS)
add_test(NAME ${NAME}
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
COMMAND test_runner lib${NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
COMMAND test_runner $<TARGET_FILE_NAME:${NAME}>
)
endif()
endif()
Expand Down
6 changes: 4 additions & 2 deletions Release/samples/BingRequest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
add_executable(BingRequest bingrequest.cpp)
target_link_libraries(BingRequest ${Casablanca_LIBRARIES})
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
add_executable(BingRequest bingrequest.cpp)
target_link_libraries(BingRequest ${Casablanca_LIBRARIES})
endif()
8 changes: 6 additions & 2 deletions Release/samples/BlackJack/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
add_subdirectory(BlackJack_Server)
add_subdirectory(BlackJack_Client)
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
add_subdirectory(BlackJack_Server)
add_subdirectory(BlackJack_Client)
else()
# TODO: add BlackJack_UIClient
endif()
15 changes: 8 additions & 7 deletions Release/samples/Oauth1Client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

add_executable(oauth1client
Oauth1Client.cpp
stdafx.cpp
)

target_link_libraries(oauth1client ${Casablanca_LIBRARIES})
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
add_executable(oauth1client
Oauth1Client.cpp
stdafx.cpp
)

target_link_libraries(oauth1client ${Casablanca_LIBRARIES})
endif()
13 changes: 7 additions & 6 deletions Release/samples/Oauth2Client/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
add_executable(oauth2client
Oauth2Client.cpp
stdafx.cpp
)

add_executable(oauth2client
Oauth2Client.cpp
stdafx.cpp
)

target_link_libraries(oauth2client ${Casablanca_LIBRARIES})
target_link_libraries(oauth2client ${Casablanca_LIBRARIES})
endif()
6 changes: 4 additions & 2 deletions Release/samples/SearchFile/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
add_executable(SearchFile searchfile.cpp)
target_link_libraries(SearchFile ${Casablanca_LIBRARIES})
if (NOT WINDOWS_STORE AND NOT WINDOWS_PHONE)
add_executable(SearchFile searchfile.cpp)
target_link_libraries(SearchFile ${Casablanca_LIBRARIES})
endif()
83 changes: 57 additions & 26 deletions Release/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,21 @@ if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
include_directories(${Boost_INCLUDE_DIR} ${OPENSSL_INCLUDE_DIR})
endif()

add_definitions(${WARNINGS})

file(GLOB SOURCES_CPPREST "../include/cpprest/*.h")
file(GLOB SOURCES_PPLX "../include/pplx/*.h")
file(GLOB SOURCES_DETAILS "../include/cpprest/details/*.h")
source_group("Header Files\\cpprest" FILES ${SOURCES_CPPREST})
source_group("Header Files\\pplx" FILES ${SOURCES_PPLX})
source_group("Header Files\\cpprest\\details" FILES ${SOURCES_DETAILS})
set(SOURCES_COMMON
${SOURCES_CPPREST}
${SOURCES_PPLX}
${SOURCES_DETAILS}
http/client/http_client.cpp
http/client/http_client_msg.cpp
http/client/http_client_impl.h
http/client/x509_cert_utilities.cpp
http/common/http_helpers.cpp
http/common/http_msg.cpp
Expand All @@ -25,7 +38,6 @@ set(SOURCES_COMMON
utilities/web_utilities.cpp
websockets/client/ws_msg.cpp
websockets/client/ws_client.cpp
websockets/client/ws_client_wspp.cpp
)

# THE ORDER OF FILES IS VERY /VERY/ IMPORTANT
Expand All @@ -37,6 +49,9 @@ if(UNIX)
http/client/http_client_asio.cpp
http/listener/http_server_asio.cpp
)
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
list(APPEND SOURCES websockets/client/ws_client_wspp.cpp)
endif()
if(APPLE)
list(APPEND SOURCES
pplx/pplxapple.cpp
Expand All @@ -55,45 +70,61 @@ if(UNIX)
endif()

if(WERROR)
set(WARNINGS "${WARNINGS} -Werror")
add_compile_options(-Werror)
endif()
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS} -pedantic")
add_compile_options(-pedantic)
elseif(WIN32)
set(SOURCES
${SOURCES_COMMON}
http/client/http_client_winhttp.cpp
http/client/x509_cert_utilities_win32.cpp
http/listener/http_server_httpsys.cpp
set(SOURCES ${SOURCES_COMMON}
pplx/pplxwin.cpp
streams/fileio_win32.cpp
pch/stdafx.cpp
)
set(EXTRALINKS
bcrypt.lib
crypt32.lib
httpapi.lib
Winhttp.lib
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNINGS}")
if (${CMAKE_GENERATOR} MATCHES "Visual Studio .*")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Yustdafx.h /Zm200")
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")
if (WINDOWS_PHONE OR WINDOWS_STORE)
list(APPEND SOURCES
http/client/http_client_winrt.cpp
streams/fileio_winrt.cpp
websockets/client/ws_client_winrt.cpp
)
else()
list(APPEND SOURCES
http/client/http_client_winhttp.cpp
http/listener/http_server_httpsys.cpp
streams/fileio_win32.cpp
)
if (NOT CPPREST_EXCLUDE_WEBSOCKETS)
list(APPEND SOURCES websockets/client/ws_client_wspp.cpp)
endif()
set(EXTRALINKS
bcrypt.lib
crypt32.lib
httpapi.lib
Winhttp.lib
)
endif()
add_compile_options(/Yustdafx.h /Zm200)
set_source_files_properties(pch/stdafx.cpp PROPERTIES COMPILE_FLAGS "/Ycstdafx.h")

if (NOT ${CMAKE_GENERATOR} MATCHES "Visual Studio .*")
set_property(SOURCE pch/stdafx.cpp APPEND PROPERTY OBJECT_OUTPUTS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
set_property(SOURCE ${SOURCES} APPEND PROPERTY OBJECT_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/stdafx.pch")
endif()

list(APPEND SOURCES pch/stdafx.cpp pch/stdafx.h)

if (BUILD_SHARED_LIBS)
add_definitions(-D_ASYNCRT_EXPORT -D_PPLX_EXPORT -D_USRDLL)
endif()
endif()

add_library(${Casablanca_LIBRARY} ${SOURCES})
add_library(cpprest ${SOURCES})

target_link_libraries(${Casablanca_LIBRARY}
target_link_libraries(cpprest
${CMAKE_THREAD_LIBS_INIT}
${Boost_SYSTEM_LIBRARY}
${Boost_THREAD_LIBRARY}
${Boost_ATOMIC_LIBRARY}
${Boost_CHRONO_LIBRARY}
${Boost_RANDOM_LIBRARY}
${Boost_REGEX_LIBRARY}
${Boost_DATE_TIME_LIBRARY}
${EXTRALINKS}
${Boost_FRAMEWORK}
${OPENSSL_LIBRARIES}
Expand All @@ -107,17 +138,17 @@ set (CPPREST_VERSION_MINOR 8)
set (CPPREST_VERSION_REVISION 0)

if(WIN32)
set_target_properties(${Casablanca_LIBRARY} PROPERTIES
OUTPUT_NAME "${Casablanca_LIBRARY}_${CPPREST_VERSION_MAJOR}_${CPPREST_VERSION_MINOR}")
set_target_properties(cpprest PROPERTIES
OUTPUT_NAME "cpprest_${CPPREST_VERSION_MAJOR}_${CPPREST_VERSION_MINOR}")
elseif(ANDROID)
# Do not use SOVERSION on android. It is completely unsupported (and causes problems).
# Perhaps revisit in the future? (NDK r9d, 8/7/14)
else()
set_target_properties(${Casablanca_LIBRARY} PROPERTIES
set_target_properties(cpprest PROPERTIES
SOVERSION ${CPPREST_VERSION_MAJOR}.${CPPREST_VERSION_MINOR})

install(
TARGETS ${Casablanca_LIBRARY}
TARGETS cpprest
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
Expand Down
8 changes: 8 additions & 0 deletions Release/src/build/vs14.android/casablanca140.android.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,10 @@
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<UseMultiToolTask>true</UseMultiToolTask>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">
<UseMultiToolTask>true</UseMultiToolTask>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
<ClCompile>
Expand Down Expand Up @@ -113,6 +115,12 @@
<PropertyGroup>
<TargetName>$(CppRestBaseFileName)140$(DebugFileSuffix)_android_$(CppRestSDKVersionFileSuffix)</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">
<UseMultiToolTask>true</UseMultiToolTask>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
<UseMultiToolTask>true</UseMultiToolTask>
</PropertyGroup>
<Import Project="..\common.vcxitems" Label="Shared" Condition="Exists('..\common.vcxitems')" />
<Import Project="..\android.vcxitems" Label="Shared" Condition="Exists('..\android.vcxitems')" />
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
Loading

0 comments on commit 834491e

Please sign in to comment.