Skip to content

Commit 0a54521

Browse files
cen1carlbennett
authored andcommitted
conan support
1 parent 0358311 commit 0a54521

10 files changed

Lines changed: 85 additions & 2240 deletions

File tree

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ Release/
3535
Thumbs.db
3636
build/
3737
cmake_install.cmake
38+
Findmpir.cmake
39+
conan.lock
40+
conanbuildinfo.txt
41+
conaninfo.txt
42+
graph_info.json

CMake/Modules/FindMPIR.cmake

Lines changed: 0 additions & 16 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
project(bncsutil)
2-
cmake_minimum_required(VERSION 2.6)
2+
cmake_minimum_required(VERSION 3.2)
3+
4+
set(CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} "${PROJECT_SOURCE_DIR}/CMake/Modules")
5+
message(${CMAKE_BINARY_DIR})
36

47
SET(VERSION_MAJOR "1")
58
SET(VERSION_MINOR "4")
@@ -12,18 +15,20 @@ file(GLOB SOURCE
1215
file(GLOB HEADERS
1316
"src/bncsutil/*.h"
1417
)
15-
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/CMake/Modules)
1618

17-
add_library(${PROJECT_NAME} SHARED ${SOURCE} ${HEADERS})
18-
add_library(${PROJECT_NAME}_static STATIC ${SOURCE} ${HEADERS})
19+
add_library(${PROJECT_NAME} ${SOURCE} ${HEADERS})
20+
21+
if (WIN32)
22+
set(USE_GMP 0)
23+
endif()
1924

20-
if (BUILD_32)
25+
if (CMAKE_GENERATOR_PLATFORM EQUAL "x86")
2126
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
2227
MESSAGE(STATUS "Excluding 64bit library paths from search.")
2328
set_property(GLOBAL PROPERTY FIND_LIBRARY_USE_LIB64_PATHS OFF)
2429
set(ARCH_DEB i386)
2530
set(ARCH_RPM i686)
26-
elseif (BUILD_64)
31+
elseif (CMAKE_GENERATOR_PLATFORM EQUAL "x64")
2732
set_target_properties(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-m64" LINK_FLAGS "-m64")
2833
set(ARCH_DEB amd64)
2934
set(ARCH_RPM x86_64)
@@ -32,15 +37,21 @@ else()
3237
set(ARCH_RPM x86_64)
3338
endif()
3439

35-
if (USE_MPIR)
36-
find_package(MPIR REQUIRED)
37-
include_directories(src ${MPIR_INCLUDE_DIR})
38-
target_link_libraries(${PROJECT_NAME} ${MPIR_LIBRARIES})
39-
add_definitions(-DUSE_MPIR=1)
40-
else()
40+
if (USE_SYSTEM_LIBS)
4141
find_package(GMP REQUIRED)
4242
include_directories(src ${GMP_INCLUDE_DIR})
4343
target_link_libraries(${PROJECT_NAME} ${GMP_LIBRARIES})
44+
else()
45+
if (USE_GMP)
46+
find_package(gmp REQUIRED)
47+
target_include_directories(${PROJECT_NAME} PRIVATE src gmp:gmp)
48+
target_link_libraries(${PROJECT_NAME} PRIVATE gmp:gmp)
49+
else()
50+
find_package(mpir REQUIRED)
51+
target_include_directories(${PROJECT_NAME} PRIVATE src mpir::mpir)
52+
target_link_libraries(${PROJECT_NAME} PRIVATE mpir::mpir)
53+
add_definitions(-DUSE_MPIR=1)
54+
endif()
4455
endif()
4556

4657
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME bncsutil)
@@ -54,8 +65,11 @@ if(UNIX)
5465
endif()
5566

5667
if (WIN32)
57-
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DMUTIL_LIB_BUILD=1)
58-
target_link_libraries(${PROJECT_NAME} Version.lib)
68+
add_definitions(-D_CRT_SECURE_NO_WARNINGS -DMUTIL_LIB_BUILD)
69+
endif()
70+
71+
if (MSVC)
72+
set_property(DIRECTORY PROPERTY VS_STARTUP_PROJECT "bncsutil")
5973
endif()
6074

6175
install(TARGETS bncsutil RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

README.md

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,53 @@ been maintained over the course of several years by the open source Battle.net c
1212
## Usage
1313
Add `bncsutil.h` to your include directory and link against `bncsutil.lib` or `libbncsutil.so`.
1414

15-
## Building
16-
CMake is used to generate platform specific build files. The only external dependency is GMP (The GNU Multiple Precision Arithmetic Library ).
17-
It can be installed with a package manager from any major Linux distro. Debian example: `sudo apt-get install libgmp10`. To force a specific build (32bit or 64bit) build add `-DBUILD_32=1` or `-DBUILD_64=1` to CMake flags. CMake will not warn you if you are missing 32bit glibc and GMP, you must install them manually first (CentOS/Fedora: `glibc-devel.i686` and `gmp-devel.i686`).
15+
## Building with conan and CMake
16+
Conan will automatically install mpir on Windows and gmp on non-Windows platforms.
1817

19-
### Windows
18+
To force a specific build (32bit or 64bit) add `-DCMAKE_GENERATOR_PLATFORM=x86` or `-DCMAKE_GENERATOR_PLATFORM=x64` to CMake flags.
2019

21-
#### GMP
22-
If you are using an older toolchain like VS 2005 or 2008, the GMP lib and header file are already included for you in `depends/include` and `depends/lib`. You can skip this step.
23-
For newer versions of Visual Studio we recommend to use MPIR library instead which is a drop-in replacement for GMP with better Windows support.
24-
1. Go to http://mpir.org/ and download the latest source archive.
25-
2. Open the VS solution file depending on which version you use, for example build.vc14 for VS 2015.
26-
3. Make a Release build of `lib_mpir_gc` project. This produces `mpir.lib` and `mpir.h` in `build.vc14\lib_mpir_gc\Win32\Release`. Copy the header file to `depends/include` and library to `depends/lib`.
20+
### Windows Visual Studio 2019
2721

28-
#### VS build
29-
1. In root bncsutil folder run `cmake -G "Visual Studio 14 2015" -B./build -H./` if you used GMP or `cmake -G "Visual Studio 14 2015" -B./build -H./ -DUSE_MPIR=1` if you used MPIR in previous step. Change the Visual Studio version as needed.
30-
2. CMake will generate sln file in ./build. Open it and build the library.
22+
Static
23+
```
24+
conan install . -if ./build -s compiler.version=16 -s arch=x86_64 -o *:shared=False
25+
cmake -G "Visual Studio 16 2019" -B./build -DBUILD_SHARED_LIBS=0 -DCMAKE_GENERATOR_PLATFORM=Win32
26+
```
27+
28+
Shared
29+
```
30+
conan install . -if ./build -s compiler.version=16 -s arch=x86_64 -o *:shared=True
31+
cmake -G "Visual Studio 16 2019" -B./build -DBUILD_SHARED_LIBS=1 -DCMAKE_GENERATOR_PLATFORM=x64
32+
```
33+
34+
### Windows Visual Studio 2015
35+
36+
Shared
37+
```
38+
conan install . -if ./build -s compiler.version=14 -s arch=x86_64 -o *:shared=True
39+
cmake -G "Visual Studio 14 2015" -B./build -DBUILD_SHARED_LIBS=1 -DCMAKE_GENERATOR_PLATFORM=x64
40+
```
41+
42+
43+
Open `.sln` in `build` directory and build from Visual Studio.
3144

3245
### Linux
33-
1. Install GMP with the package manager. Also install all the necessary development tools (gcc, make or build-essential package on Debian).
34-
2. Run `cmake -G "Unix Makefiles" -B./build -H./`
35-
3. `cd build && make && make install`
46+
```
47+
conan install . -if ./build
48+
cmake -G "Unix Makefiles" -B./build
49+
cd build && make && make install
50+
```
51+
52+
## Building using system dependencies
53+
Instead of using conan you can link against system provided gmp. Install `libgmp-dev` on deb distros or `gmp-devel` on rpm distros. For 32bit builds, CMake will not warn you if you are missing 32bit glibc and GMP, you must install them manually first (CentOS/Fedora: `glibc-devel.i686` and `gmp-devel.i686`).
54+
55+
```
56+
cmake -G "Unix Makefiles" -B./build
57+
cd build && make && make install
58+
```
3659

3760
## Building .deb and .rpm packages
38-
After invoking cmake, cd to build folder and generate them with `cpack -G "DEB"` and `cpack -G "RPM"`.
61+
After invoking CMake, cd to build folder and generate them with `cpack -G "DEB"` and `cpack -G "RPM"`.
3962
You can then use `gdebi` to do a local install of .deb with automatic dependency resolution or `yum localinstall` on rpm distros. For dnf it's just `dnf install <name>.rpm`.
4063

4164
## Hosted Linux repositories

conanfile.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from conans import ConanFile, CMake
2+
3+
class Bncsutil(ConanFile):
4+
settings = "os", "compiler", "build_type", "arch"
5+
generators = "cmake_find_package"
6+
7+
def requirements(self):
8+
if self.settings.os == "Windows":
9+
self.requires("mpir/3.0.0")
10+
else:
11+
self.requires("gmp/6.2.0")

depends/include/README.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)