Skip to content

Commit f331825

Browse files
committed
initial commit for building through CMake in Windows
1 parent dede5f6 commit f331825

File tree

4 files changed

+61
-12
lines changed

4 files changed

+61
-12
lines changed

CMakeLists.txt

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,32 @@ set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation direc
55
set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
66
set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
77

8+
function(install_windows_deps)
9+
# Bootstrap vcpkg from CMake and auto-install deps in case if we are missing
10+
# deps on Windows. Respect the target architecture variable.
11+
set(VCPKG_TARGET_ARCHITECTURE
12+
${ARCH}
13+
PARENT_SCOPE)
14+
message("Installing build tools and dependencies...")
15+
set(ENV{ARCH} ${ARCH})
16+
execute_process(
17+
COMMAND ${CMAKE_SOURCE_DIR}/tools/setup-buildtools.cmd)
18+
set(CMAKE_TOOLCHAIN_FILE
19+
${CMAKE_SOURCE_DIR}/tools/vcpkg/scripts/buildsystems/vcpkg.cmake
20+
PARENT_SCOPE)
21+
endfunction()
22+
23+
# Autodetect vcpkg toolchain
24+
if(DEFINED ENV{VCPKG_ROOT} AND NOT DEFINED CMAKE_TOOLCHAIN_FILE)
25+
set(CMAKE_TOOLCHAIN_FILE
26+
"$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
27+
CACHE STRING "")
28+
endif()
29+
30+
if(VCPKG_CHAINLOAD_TOOLCHAIN_FILE)
31+
include("${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}")
32+
endif()
33+
834
# Begin Uncomment for i386 build
935
#set(CMAKE_SYSTEM_PROCESSOR i386)
1036
#set(CMAKE_C_FLAGS -m32)
@@ -295,7 +321,7 @@ endif()
295321
# Packaging
296322
################################################################################################
297323

298-
if (BUILD_PACKAGE)
324+
if (BUILD_PACKAGE AND (NOT WIN32))
299325
if (${CMAKE_PACKAGE_TYPE} STREQUAL "deb")
300326
# FIXME: hardcode it for 64-bit Linux for now
301327
set(INSTALL_LIB_DIR ${CMAKE_INSTALL_PREFIX}/lib/${CPACK_DEBIAN_ARCHITECTURE}-linux-gnu)

tests/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ if(BUILD_UNIT_TESTS)
2222
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/unittests)
2323
add_subdirectory(unittests)
2424
endif()
25+
26+
if (WIN32 AND (BUILD_FUNC_TESTS OR BUILD_UNIT_TEST))
27+
message("LALIT-->Checkig..")
28+
find_package(GTest)
29+
if(NOT (GTEST_FOUND OR GTest_FOUND))
30+
install_windows_deps()
31+
if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)
32+
message(STATUS_FATAL "Windows dependency installation failed!")
33+
endif()
34+
message(STATUS ${CMAKE_TOOLCHAIN_FILE})
35+
find_package(GTest REQUIRED)
36+
endif()
37+
endif()

tests/functests/CMakeLists.txt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ endif()
3030

3131
if (EXISTS ${CMAKE_SOURCE_DIR}/lib/modules/exp/tests)
3232
list(APPEND SRCS
33-
${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/functests/ECSClientFuncTests.cpp
33+
${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/functests/ECSClientFuncTestzlibs.cpp
3434
${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/functests/ECSClientRealworldFuncTests.cpp
3535
${CMAKE_SOURCE_DIR}/lib/modules/exp/tests/functests/ECSConfigCacheFuncTests.cpp
3636
)
@@ -46,21 +46,25 @@ else()
4646
endif()
4747

4848
if(PAL_IMPLEMENTATION STREQUAL "WIN32")
49+
find_package(gtest REQUIRED)
50+
find_package(sqlite3 REQUIRED)
51+
find_package( ZLIB REQUIRED )
4952
# Link against prebuilt libraries on Windows
5053
message("--- WIN32: Linking against prebuilt libraries")
51-
message("--- WIN32: ... ${CMAKE_BINARY_DIR}/gtest")
52-
message("--- WIN32: ... ${CMAKE_BINARY_DIR}/gmock")
53-
message("--- WIN32: ... ${CMAKE_BINARY_DIR}/zlib")
5454
message("--- WIN32: ... ${CMAKE_BINARY_DIR}/sqlite")
55-
# link_directories(${CMAKE_BINARY_DIR}/gtest/ ${CMAKE_BINARY_DIR}/gmock/ ${CMAKE_BINARY_DIR}/zlib/ ${CMAKE_BINARY_DIR}/sqlite/)
56-
include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../../zlib )
55+
include_directories(SYSTEM ${GTEST_INCLUDE_DIRS})
56+
include_directories( ${ZLIB_INCLUDE_DIRS} )
57+
message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
58+
message("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
59+
message("SQLITE3_LIBRARIES = ${SQLITE3_LIBRARIES}")
60+
message("ZLIB_LIBRARIES = ${ZLIB_LIBRARIES}")
61+
5762
target_link_libraries(FuncTests
5863
mat
5964
wininet.lib
60-
${CMAKE_BINARY_DIR}/gtest/gtest.lib
61-
${CMAKE_BINARY_DIR}/gmock/gmock.lib
62-
${CMAKE_BINARY_DIR}/zlib/zlib.lib
63-
${CMAKE_BINARY_DIR}/sqlite/sqlite.lib
65+
${GTEST_BOTH_LIBRARIES}
66+
${SQLite3_LIBRARIES}
67+
${ZLIB_LIBRARIES}
6468
)
6569
else()
6670

tools/setup-buildtools.cmd

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ if ERRORLEVEL 0 (
1717
)
1818

1919
REM Install tools needed to build SDK with either Visual Studio or CMake
20-
choco install -y cmake svn git llvm zip
20+
where /Q vswhere || choco install -y vswhere
21+
where /Q cmake || choco install -y cmake
22+
where /Q git || choco install -y git
23+
where /Q llvm || choco install -y llvm
24+
where /Q zip || choco install -y zip
2125

2226
REM Try to autodetect Visual Studio
2327
call "%~dp0\vcvars.cmd"
@@ -55,6 +59,8 @@ REM Install it
5559
vcpkg install gtest:x64-windows
5660
vcpkg install --overlay-ports=%~dp0\ports benchmark:x64-windows
5761
vcpkg install ms-gsl:x64-windows
62+
vcpkg install zlib:x64-windows
63+
vcpkg install sqlite3:x64-windows
5864

5965
if DEFINED INSTALL_LLVM (
6066
REM Required for LLVM Clang build on Windows

0 commit comments

Comments
 (0)