-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
74 lines (66 loc) · 2.71 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
cmake_minimum_required(VERSION 3.1)
project (basilisk_hunter C CXX ASM)
add_subdirectory(cpu_features)
#todo: modularize the cmake file
#todo: make release/debug targets
set (VERSION_MAJOR 0)
set (VERSION_MINOR 1)
set (VERSION_PATCH 0)
include_directories(include)
include_directories(src)
file(GLOB_RECURSE SOURCES "src/*.cpp" "src/*.h" "src/*.c")
find_package(Git)
find_program(PYTHON_EXE NAMES python3 py)
set(VERSION_CPP_FILE "${PROJECT_BINARY_DIR}/src/version.cpp")
set(VERSION_GENERATOR_SCRIPT "${PROJECT_SOURCE_DIR}/src/generate_version.py")
set(VERSION_DEPENDS ${VERSION_GENERATOR_SCRIPT} ${SOURCES})
set(GIT_INDEX "${PROJECT_SOURCE_DIR}/.git/index")
if(EXISTS GIT_INDEX)
set(VERSION_DEPENDS GIT_INDEX ${VERSION_DEPENDS})
endif()
add_custom_command(
OUTPUT ${VERSION_CPP_FILE}
COMMAND ${PYTHON_EXE}
ARGS ${VERSION_GENERATOR_SCRIPT} ${VERSION_CPP_FILE} ${CMAKE_PROJECT_NAME} "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}" "${GIT_EXECUTABLE}"
DEPENDS ${VERSION_DEPENDS})
set(SOURCES ${VERSION_CPP_FILE} ${SOURCES})
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "x86_64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "AMD64")
find_program(YASM_EXE NAMES yasm)
if(${CMAKE_SYSTEM_NAME} MATCHES "Linux" OR ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
set(YASM_ARGS "-f" "x64" "-f" "elf64" "-X" "gnu" "-g" "dwarf2" "-D" "LINUX")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
set(YASM_ARGS "-f" "x64" "-f" "macho64" "-D" "MANGLE" "-D" "LINUX")
elseif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
set(YASM_ARGS "-Xvc" "-f" "x64" "-rnasm" "-pnasm" "-g" "cv8")
else()
message( FATAL_ERROR "TODO: don't know how to compile yasm on ${CMAKE_SYSTEM_NAME}." )
endif()
set(YASM_OBJECTS)
file(GLOB_RECURSE YASM_SOURCES "src/*.yasm")
foreach(YASM_SOURCE ${YASM_SOURCES})
get_filename_component(YASM_SOURCE_NAME ${YASM_SOURCE} NAME)
set(YASM_OBJECT ${CMAKE_CURRENT_BINARY_DIR}/${YASM_SOURCE_NAME}.o)
set(YASM_OBJECTS ${YASM_OBJECTS} ${YASM_OBJECT})
add_custom_command(
OUTPUT ${YASM_OBJECT}
COMMAND ${YASM_EXE}
ARGS ${YASM_ARGS} -o ${YASM_OBJECT} ${YASM_SOURCE}
MAIN_DEPENDENCY ${YASM_SOURCE} )
endforeach()
endif()
if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
set(SOURCES "src/crypto/impl/bits_arm/sha256-armv8-aarch64.S" ${SOURCES})
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
set(CMAKE_CXX_STANDARD 11)
add_executable(basilisk_hunter ${SOURCES} ${YASM_OBJECTS} "resources.rc")
target_link_libraries(basilisk_hunter Threads::Threads cpu_features ${CPR_LIBRARIES})
if(MSVC)
set(CMAKE_CXX_FLAGS "/O2 /W4 /WX /EHsc /GL")
set(CMAKE_EXE_LINKER_FLAGS "/LTCG")
else()
set(CMAKE_C_FLAGS "-O3 -Werror -Wall -Wextra -flto -march=native")
set(CMAKE_CXX_FLAGS "-O3 -Werror -Wall -Wextra -flto -march=native")
set(CMAKE_EXE_LINKER_FLAGS "-flto")
endif()