Skip to content

Commit

Permalink
cmake uses clang++
Browse files Browse the repository at this point in the history
  • Loading branch information
herumi committed Oct 4, 2022
1 parent d86e11b commit 7d4a652
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 59 deletions.
32 changes: 8 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,17 @@ if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
add_dependencies(mcl gen_bint-x64-win.obj)
target_link_libraries(mcl_st PUBLIC ${BINT_X64_OBJ})
add_dependencies(mcl_st gen_bint-x64-win.obj)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
target_sources(mcl PRIVATE src/asm/bint-x64-amd64.s)
target_sources(mcl_st PRIVATE src/asm/bint-x64-amd64.s)
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
target_sources(mcl PRIVATE src/asm/bint64-Linux-aarch64.s)
target_sources(mcl_st PRIVATE src/asm/bint64-Linux-aarch64.s)
else()
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ...")
endif()
set(BINT_OBJ "${CMAKE_CURRENT_BINARY_DIR}/bint${BIT}.o")
message("bint_obj=" ${BINT_OBJ})
target_compile_definitions(mcl PUBLIC MCL_BINT_ASM_X64=0)
target_compile_definitions(mcl_st PUBLIC MCL_BINT_ASM_X64=0)
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ...")
endif()

add_custom_command(OUTPUT ${BINT_OBJ}
COMMAND ${CMAKE_CXX_COMPILER} -c -o ${BINT_OBJ} ${CMAKE_CURRENT_SOURCE_DIR}/src/bint${BIT}.ll -O3 -fPIC
Expand All @@ -179,25 +176,12 @@ endif()

if(CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64") # Win64
# skip
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64" AND NOT APPLE)
target_compile_definitions(mcl PUBLIC MCL_USE_LLVM=1)
target_compile_definitions(mcl_st PUBLIC MCL_USE_LLVM=1)
if(APPLE)
target_sources(mcl PRIVATE src/asm/x86-64mac.s)
target_sources(mcl_st PRIVATE src/asm/x86-64mac.s)
else()
target_sources(mcl PRIVATE src/asm/x86-64.s)
target_sources(mcl_st PRIVATE src/asm/x86-64.s)
endif()
elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
target_compile_definitions(mcl PUBLIC MCL_USE_LLVM=1)
target_compile_definitions(mcl_st PUBLIC MCL_USE_LLVM=1)
target_sources(mcl PRIVATE src/asm/aarch64.s)
target_sources(mcl_st PRIVATE src/asm/aarch64.s)
elif(${MCL_USE_LLVM})
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "Clang")
message(FATAL_ERROR "requiring clang++. cmake -DCMAKE_CXX_COMPILER=clang++ ...")
endif()
target_sources(mcl PRIVATE src/asm/x86-64.s)
target_sources(mcl_st PRIVATE src/asm/x86-64.s)
elseif(${MCL_USE_LLVM})
set(BASE_OBJ "${CMAKE_CURRENT_BINARY_DIR}/base${BIT}.o")
message("base_obj=" ${BASE_OBJ})
target_compile_definitions(mcl PUBLIC MCL_USE_LLVM=1)
Expand Down
80 changes: 45 additions & 35 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,60 @@ x86-64/ARM/ARM64 Linux, macOS and mingw64 are supported.

## How to build with Makefile

For x86-64 Linux and macOS,

```
git clone https://github.com/herumi/mcl
cd mcl
make -j4
```
clang++ is required except for x86-64 on Linux and Windows.

```
make -j4 CXX=clang++
```

- `lib/libmcl.*` ; core library
- `lib/libmclbn384_256.*` ; library to use C-API of BLS12-381 pairing

# How to build with CMake

For x86-64 Linux and macOS.
```
mkdir build
cd build
cmake ..
make
```

For the other platform, clang++ is required.
```
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++
make
```

For Visual Studio,
```
mkdir build
cd build
cmake .. -A x64
msbuild mcl.sln /p:Configuration=Release /m
```

## options

see `cmake .. -LA`.

## tests
make test binaries in `./bin`.
```
cmake .. -DBUILD_TESTING=ON
make -j4
```


## How to make from src/{base,bint}{32,64}.ll

clang (clang-cl on Windows) is necessary to build files with a suffix ll.
Expand Down Expand Up @@ -149,41 +194,6 @@ cd ../../bin
../ffi/cs/test/bin/Debug/netcoreapp3.1/test.exe
```

# How to build with CMake

For Linux, macOS, etc.
```
mkdir build
cd build
cmake ..
make
```
For Visual Studio,
```
mkdir build
cd build
cmake .. -A x64
msbuild mcl.sln /p:Configuration=Release /m
```

Some architectures requre clang.
```
mkdir build
cd build
cmake .. -DCMAKE_CXX_COMPILER=clang++
```

## options

see `cmake .. -LA`.

## tests
make test binaries in `./bin`.
```
cmake .. -DBUILD_TESTING=ON
make -j4
```

# How to build for wasm(WebAssembly)
mcl supports emcc (Emscripten) and `test/bn_test.cpp` runs on browers such as Firefox, Chrome and Edge.

Expand Down

0 comments on commit 7d4a652

Please sign in to comment.