Skip to content

Commit

Permalink
Make commonpp complient with vcpkg
Browse files Browse the repository at this point in the history
* Boost version is really up to date so manually add date_time deps;
* Windows compliant FindHWLOC.cmake
* If hwloc is not found, logger.cpp should still be configured.
  • Loading branch information
daedric committed Sep 5, 2017
1 parent e7785d3 commit 79d587b
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 24 deletions.
17 changes: 10 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,17 @@ if (HWLOC_FOUND)
endif()

#Boost
if (${BUILD_SHARED_LIBS})
set(Boost_USE_STATIC_LIBS OFF)
add_definitions("-DBOOST_ALL_DYN_LINK=1")
ELSE()
set(Boost_USE_STATIC_LIBS ON)
if (NOT WIN32)
if (${BUILD_SHARED_LIBS})
set(Boost_USE_STATIC_LIBS OFF)
add_definitions("-DBOOST_ALL_DYN_LINK=1")
ELSE()
set(Boost_USE_STATIC_LIBS ON)
endif()

set(Boost_USE_MULTITHREADED ON)
endif()

set(Boost_USE_MULTITHREADED ON)

if ("${CMAKE_SYSTEM_NAME}" MATCHES "Linux")
set(HAVE_SYSLOG 1)
endif()
Expand All @@ -139,6 +141,7 @@ find_package(Boost 1.54.0
unit_test_framework
log
log_setup
date_time
filesystem
thread
system
Expand Down
17 changes: 17 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
[![Build status](https://ci.appveyor.com/api/projects/status/uicpe9aefv7ufiqs/branch/master?svg=true)](https://ci.appveyor.com/project/daedric/commonpp/branch/master)

# CommonPP

`commonpp` is a multi purpose library easing very few operations like:
Expand Down Expand Up @@ -27,6 +29,21 @@ It builds on Mac OS X and Linux. It probably build on *BSD but I did not test
$> make
$> make test

#### On windows

`commonpp` can be built and used on windows. The prefered way is to use
`vcpkg`.

The required dependencies can be installed using the following command:

$> .\vcpkg.exe install boost:x64-windows tbb:x64-windows hwloc:x64-windows

Then you can generate a Visual Studio solution giving the vcpkg toolchain file.

Please note that only VS2017 has been tested. Also, static `TBB` installation
cannot be done, so the DLL will need to be in the path to execute binaries
depending on `commonpp`.

### Why?

Although Boost and TBB are very complete low-level libraries, there are still
Expand Down
26 changes: 26 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 1.0.{build}
image: Visual Studio 2017
configuration: Debug, Release
clone_folder: c:\code\commonpp
init:
- ps: vcpkg install boost:x64-windows hwloc:x64-windows tbb:x64-windows
environment:
matrix:
- FLAVOR: Debug
- FLAVOR: Release
build_script:
- cmd: >-
cd c:\code
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=C:\Tools\vcpkg\scripts\buildsystems\vcpkg.cmake -G "Visual Studio 15 2017 Win64" c:\code\commonpp
cmake --build . --target ALL_BUILD --config %FLAVOR%
test_script:
- cmd: >-
cd C:\code\build
cmake --build . --target RUN_TESTS --config %FLAVOR%
190 changes: 177 additions & 13 deletions cmake/FindHWLOC.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,181 @@
INCLUDE(LibFindMacros)
#.rst:
# FindHWLOC
# ----------
#
# Try to find Portable Hardware Locality (HWLOC) libraries.
# http://www.open-mpi.org/software/hwloc
#
# You may declare HWLOC_ROOT environment variable to tell where
# your hwloc library is installed.
#
# Once done this will define::
#
# HWLOC_FOUND - True if hwloc was found
# HWLOC_INCLUDE_DIRS - include directories for hwloc
# HWLOC_LIBRARIES - link against these libraries to use hwloc
# HWLOC_VERSION - version
# HWLOC_CFLAGS - include directories as compiler flags
# HWLOC_LDLFAGS - link paths and libs as compiler flags
#

LIBFIND_PKG_CHECK_MODULES(HWLOC_PKGCONF hwloc)
#=============================================================================
# Copyright 2014 Mikael Lepistö
#
# Distributed under the OSI-approved BSD License (the "License");
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================

FIND_PATH(HWLOC_INCLUDE_DIR
NAMES hwloc.h
PATHS ${HWLOC_PKGCONF_INCLUDE_DIRS}
)
if(WIN32)
find_path(HWLOC_INCLUDE_DIR
NAMES
hwloc.h
PATHS
ENV "PROGRAMFILES(X86)"
ENV HWLOC_ROOT
PATH_SUFFIXES
include
)

FIND_LIBRARY(HWLOC_LIBRARY
NAMES hwloc
PATHS ${HWLOC_PKGCONF_LIBRARY_DIRS}
)
find_library(HWLOC_LIBRARY
NAMES
libhwloc.lib
PATHS
ENV "PROGRAMFILES(X86)"
ENV HWLOC_ROOT
PATH_SUFFIXES
lib
)

#
# Check if the found library can be used to linking
#
SET (_TEST_SOURCE "${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/linktest.c")
FILE (WRITE "${_TEST_SOURCE}"
"
#include <hwloc.h>
int main()
{
hwloc_topology_t topology;
int nbcores;
hwloc_topology_init(&topology);
hwloc_topology_load(topology);
nbcores = hwloc_get_nbobjs_by_type(topology, HWLOC_OBJ_CORE);
hwloc_topology_destroy(topology);
return 0;
}
"
)

TRY_COMPILE(_LINK_SUCCESS ${CMAKE_BINARY_DIR} "${_TEST_SOURCE}"
CMAKE_FLAGS
"-DINCLUDE_DIRECTORIES:STRING=${HWLOC_INCLUDE_DIR}"
CMAKE_FLAGS
"-DLINK_LIBRARIES:STRING=${HWLOC_LIBRARY}"
)

IF(NOT _LINK_SUCCESS)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "You are building 64bit target.")
ELSE()
message(STATUS "You are building 32bit code. If you like to build x64 use e.g. -G 'Visual Studio 12 Win64' generator." )
ENDIF()
message(FATAL_ERROR "Library found, but linking test program failed.")
ENDIF()

#
# Resolve version if some compiled binary found...
#
find_program(HWLOC_INFO_EXECUTABLE
NAMES
hwloc-info
PATHS
ENV HWLOC_ROOT
PATH_SUFFIXES
bin
)

if(HWLOC_INFO_EXECUTABLE)
execute_process(
COMMAND ${HWLOC_INFO_EXECUTABLE} "--version"
OUTPUT_VARIABLE HWLOC_VERSION_LINE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
string(REGEX MATCH "([0-9]+.[0-9]+)$"
HWLOC_VERSION "${HWLOC_VERSION_LINE}")
unset(HWLOC_VERSION_LINE)
endif()

#
# All good
#

set(HWLOC_LIBRARIES ${HWLOC_LIBRARY})
set(HWLOC_INCLUDE_DIRS ${HWLOC_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(
HWLOC
FOUND_VAR HWLOC_FOUND
REQUIRED_VARS HWLOC_LIBRARY HWLOC_INCLUDE_DIR
VERSION_VAR HWLOC_VERSION)

mark_as_advanced(
HWLOC_INCLUDE_DIR
HWLOC_LIBRARY)

foreach(arg ${HWLOC_INCLUDE_DIRS})
set(HWLOC_CFLAGS "${HWLOC_CFLAGS} /I${arg}")
endforeach()

set(HWLOC_LDFLAGS "${HWLOC_LIBRARY}")

else()

# Find with pkgconfig
find_package(PkgConfig)

if(HWLOC_ROOT)
set(ENV{PKG_CONFIG_PATH} "${HWLOC_ROOT}/lib/pkgconfig")
else()
foreach(PREFIX ${CMAKE_PREFIX_PATH})
set(PKG_CONFIG_PATH "${PKG_CONFIG_PATH}:${PREFIX}/lib/pkgconfig")
endforeach()
set(ENV{PKG_CONFIG_PATH} "${PKG_CONFIG_PATH}:$ENV{PKG_CONFIG_PATH}")
endif()

if(HWLOC_FIND_REQUIRED)
set(_HWLOC_OPTS "REQUIRED")
elseif(HWLOC_FIND_QUIETLY)
set(_HWLOC_OPTS "QUIET")
else()
set(_HWLOC_output 1)
endif()

if(HWLOC_FIND_VERSION)
if(HWLOC_FIND_VERSION_EXACT)
pkg_check_modules(HWLOC ${_HWLOC_OPTS} HWLOC=${HWLOC_FIND_VERSION})
else()
pkg_check_modules(HWLOC ${_HWLOC_OPTS} HWLOC>=${HWLOC_FIND_VERSION})
endif()
else()
pkg_check_modules(HWLOC ${_HWLOC_OPTS} HWLOC)
endif()

if(HWLOC_FOUND)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(HWLOC DEFAULT_MSG HWLOC_LIBRARIES)

if(NOT ${HWLOC_VERSION} VERSION_LESS 1.7.0)
set(HWLOC_GL_FOUND 1)
endif()

if(_HWLOC_output)
message(STATUS
"Found HWLOC ${HWLOC_VERSION} in ${HWLOC_INCLUDE_DIRS}:${HWLOC_LIBRARIES}")
endif()
endif()
endif()

SET(HWLOC_PROCESS_INCLUDES HWLOC_INCLUDE_DIR)
SET(HWLOC_PROCESS_LIBS HWLOC_LIBRARY)
LIBFIND_PROCESS(HWLOC)
16 changes: 12 additions & 4 deletions src/commonpp/thread/detail/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@
# Copyright (c) 2016 Thomas Sanchez. All rights reserved.
#

set(srcs
logger.cpp
)

if (NOT HWLOC_FOUND)
return ()
message(WARNING "HWLOC has not been found, thread pining is disabled.")
else()
set(srcs
${srcs}
Core.cpp
Cores.cpp
)
endif()

add_commonpp_library_source(
SOURCES
Core.cpp
Cores.cpp
logger.cpp)
${srcs}
)

0 comments on commit 79d587b

Please sign in to comment.