Skip to content

Commit

Permalink
common: enable building on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
igchor committed Jun 16, 2018
1 parent 204ca6f commit e3853f9
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 69 deletions.
44 changes: 25 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ find_package(PkgConfig QUIET)

include_directories(include)

# Treat CMAKE_CXX_STANDARD as a requirement
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_STANDARD 11)

function(join SEP OUT VALUES)
Expand Down Expand Up @@ -292,7 +294,7 @@ add_custom_target(uninstall
if(PKG_CONFIG_FOUND)
pkg_check_modules(PMEMOBJ REQUIRED libpmemobj>=1.4)
else()
find_package(PMEMOBJ REQUIRED)
find_package(PMEMOBJ REQUIRED 1.4)
endif()

if(PKG_CONFIG_FOUND)
Expand Down Expand Up @@ -325,24 +327,28 @@ if(NOT LIBUNWIND_FOUND)
message(WARNING "libunwind not found. Stack traces from tests will not be reliable")
endif()

set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})

# Check for issues with older gcc compilers which do not expand variadic template
# variables in lambda expressions.
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -c")
CHECK_CXX_SOURCE_COMPILES(
"void print() {}
template<typename...Args, typename T>
void print(const T&, const Args &...arg) {
auto f = [&]{ print(arg...);};
}
int main() {
print(1, 2, 3);
return 0;
}"
NO_GCC_VARIADIC_TEMPLATE_BUG)

set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
if(NOT WIN32)
set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})

# Check for issues with older gcc compilers which do not expand variadic template
# variables in lambda expressions.
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -c")
CHECK_CXX_SOURCE_COMPILES(
"void print() {}
template<typename...Args, typename T>
void print(const T&, const Args &...arg) {
auto f = [&]{ print(arg...);};
}
int main() {
print(1, 2, 3);
return 0;
}"
NO_GCC_VARIADIC_TEMPLATE_BUG)

set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
else()
set(NO_GCC_VARIADIC_TEMPLATE_BUG TRUE)
endif()

if(BUILD_TESTS)
if(TEST_DIR)
Expand Down
31 changes: 11 additions & 20 deletions examples/pmpong/buildScript.ps1 → FindPMEMOBJ.cmake
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2017, Intel Corporation
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand Down Expand Up @@ -27,22 +28,12 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# buildScript.ps1 -- script for downloading and copying SFML files
#
$url = "https://www.sfml-dev.org/files/SFML-2.4.2-windows-vc14-64-bit.zip"
$Filename = [System.IO.Path]::GetFileName($url)
$path = "$env:TEMP\$Filename"
$webClient = new-object System.Net.WebClient
$webClient.DownloadFile($url,$path)
$SFMLFileExists = Test-Path $env:TEMP\SFML-2.4.2
if ($SFMLFileExists -eq $False) {
$shell = New-Object -ComObject shell.application
$zip = $shell.NameSpace($path)
foreach ($item in $zip.items()) {
$shell.Namespace($env:TEMP).CopyHere($item)
}
}
Copy-Item $env:TEMP\SFML-2.4.2\bin\* -Destination $env:TargetDir
Copy-Item $env:TEMP\SFML-2.4.2\include -Destination $env:TargetDir -recurse
Copy-Item $env:TEMP\SFML-2.4.2\lib -Destination $env:TargetDir -recurse

find_path(PMEMOBJ_INCLUDE_DIR libpmemobj.h HINTS ${PMEMOBJ_PATH}/include)
find_library(PMEMOBJ_LIBRARY libpmemobj HINTS ${PMEMOBJ_PATH}/lib)
find_library(PMEM_LIBRARY libpmem HINTS ${PMEMOBJ_PATH}/lib)

set(PMEMOBJ_LIBRARIES ${PMEMOBJ_LIBRARY} ${PMEM_LIBRARY})
set(PMEMOBJ_INCLUDE_DIRS ${PMEMOBJ_INCLUDE_DIR})

mark_as_advanced(PMEMOBJ_LIBRARY PMEM_LIBRARY PMEMOBJ_INCLUDE_DIR)
9 changes: 6 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ endif()
if(PKG_CONFIG_FOUND)
pkg_check_modules(SFML QUIET sfml-all>=2.4)
else()
find_package(SFML 2.4 QUIET all)
# SFML 2.5 has different cmake interface than <= 2.4 so previous versions are not supported
find_package(SFML 2.5 QUIET COMPONENTS graphics window system)
set(SFML_LIBRARIES sfml-graphics sfml-window sfml-system)
endif()

add_example(queue queue/queue.cpp)
Expand All @@ -70,9 +72,10 @@ else()
endif()

if(SFML_FOUND)
# XXX: this can only be run in Release mode - in Debug SFML doesn't add all dependencies automatically
add_example(pmpong pmpong/Ball.cpp pmpong/GameController.cpp pmpong/GameOverView.cpp
pmpong/GameView.cpp pmpong/MainGame.cpp pmpong/MenuView.cpp pmpong/Paddle.cpp
pmpong/PongGameStatus.cpp pmpong/Pool.cpp)
pmpong/GameView.cpp pmpong/MainGame.cpp pmpong/MenuView.cpp pmpong/Paddle.cpp
pmpong/PongGameStatus.cpp pmpong/Pool.cpp)
target_include_directories(example-pmpong PUBLIC ${SFML_INCLUDE_DIR})
target_link_libraries(example-pmpong ${PMEMOBJ_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${SFML_LIBRARIES})

Expand Down
2 changes: 2 additions & 0 deletions examples/objcpp_examples_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ find_last_set_64(uint64_t val)

#else

#include <corecrt_io.h>
#include <process.h>
#include <windows.h>

#define CREATE_MODE_RW (S_IWRITE | S_IREAD)
Expand Down
59 changes: 32 additions & 27 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,35 @@ endif()
include_directories(${INCLUDE_DIRS})
link_directories(${LIBS_DIRS})

set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(SAVED_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})

# Check for issues with older clang compilers which assert on delete persistent<[][]>.
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../include ${PMEMOBJ_INCLUDE_DIRS})
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -c")
CHECK_CXX_SOURCE_COMPILES(
"#include <libpmemobj++/make_persistent_array.hpp>
using namespace pmem::obj;
int main() {
delete_persistent<int[][3]>(make_persistent<int[][3]>(2), 2);
return 0;
}"
NO_CLANG_TEMPLATE_BUG)

# This is a workaround for older incompatible versions of libstdc++ and clang.
# Please see https://llvm.org/bugs/show_bug.cgi?id=15517 for more info.
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -include future")
CHECK_CXX_SOURCE_COMPILES(
"int main() { return 0; }"
NO_CHRONO_BUG)

set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_INCLUDES ${SAVED_CMAKE_REQUIRED_INCLUDES})
if(NOT WIN32)
set(SAVED_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
set(SAVED_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES})

# Check for issues with older clang compilers which assert on delete persistent<[][]>.
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_CURRENT_SOURCE_DIR}/../include ${PMEMOBJ_INCLUDE_DIRS})
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -c")
CHECK_CXX_SOURCE_COMPILES(
"#include <libpmemobj++/make_persistent_array.hpp>
using namespace pmem::obj;
int main() {
delete_persistent<int[][3]>(make_persistent<int[][3]>(2), 2);
return 0;
}"
NO_CLANG_TEMPLATE_BUG)

# This is a workaround for older incompatible versions of libstdc++ and clang.
# Please see https://llvm.org/bugs/show_bug.cgi?id=15517 for more info.
set(CMAKE_REQUIRED_FLAGS "--std=c++11 -include future")
CHECK_CXX_SOURCE_COMPILES(
"int main() { return 0; }"
NO_CHRONO_BUG)

set(CMAKE_REQUIRED_FLAGS ${SAVED_CMAKE_REQUIRED_FLAGS})
set(CMAKE_REQUIRED_INCLUDES ${SAVED_CMAKE_REQUIRED_INCLUDES})
else()
set(NO_CLANG_TEMPLATE_BUG TRUE)
set(NO_CHRONO_BUG TRUE)
endif()

add_cppstyle("tests-common" ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp)
add_check_whitespace("tests-common" ${CMAKE_CURRENT_SOURCE_DIR}/common/*.*pp)
Expand Down Expand Up @@ -190,21 +195,21 @@ function(add_testcase name tracer testcase)

if ((NOT VALGRIND_FOUND) AND ${tracer} IN_LIST vg_tracers)
add_test(NAME ${name}_${testcase}_${tracer}_SKIPPED_BECAUSE_OF_MISSING_VALGRIND
COMMAND true)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/true.cmake)
return()
endif()

if(${tracer} STREQUAL pmemcheck)
if (VALGRIND_PMEMCHECK_NOT_FOUND)
add_test(NAME ${name}_${testcase}_${tracer}_SKIPPED_BECAUSE_OF_MISSING_PMEMCHECK
COMMAND true)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/true.cmake)
return()
endif()
endif()

if (NOT TARGET ${name}) # if test was not build (because of compiler issue)
add_test(NAME ${name}_${testcase}_${tracer}_SKIPPED_BECAUSE_OF_COMPILER_ISSUE
COMMAND true)
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/true.cmake)
return()
endif()

Expand Down
8 changes: 8 additions & 0 deletions tests/common/unittest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ typedef struct _stat64 os_stat_t;
#define os_stat _stat64
#endif

#ifdef _WIN32
#include <windows.h>
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
#define S_IRGRP S_IRUSR
#define S_IWGRP S_IWUSR
#endif

template <typename... Args>
static inline void UT_OUT(Args... args)
{
Expand Down
34 changes: 34 additions & 0 deletions tests/true.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright 2018, Intel Corporation
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
#
# * Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# true.cmake - cmake script which always succeeds

return()

0 comments on commit e3853f9

Please sign in to comment.