Skip to content

Commit 393f751

Browse files
Deniskorebakwc
andauthored
Improve compile options (bakwc#14)
* Improve compile options * Updated binaries --------- Co-authored-by: Filipp Ozinov <[email protected]>
1 parent 853a6c6 commit 393f751

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

binlog_json_parser/CMakeLists.txt

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,55 @@
1-
cmake_minimum_required(VERSION 3.0)
1+
cmake_minimum_required(VERSION 3.20)
2+
23
project(binlog_json_parser)
34

45
set(CMAKE_CXX_STANDARD 23)
6+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
7+
8+
# Check if the build type is Release
9+
if(CMAKE_BUILD_TYPE STREQUAL "Release")
10+
11+
# Set optimization level to -O3 for release builds
12+
if(NOT CMAKE_CXX_FLAGS_RELEASE MATCHES "-O")
13+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
14+
endif()
15+
16+
# Option to add march-native for release builds
17+
option(USE_MARCH_NATIVE "Enable -march=native for release builds" OFF)
18+
19+
# Determine the architecture
20+
include(CMakeDetermineSystem)
21+
22+
if(CMAKE_SYSTEM_PROCESSOR MATCHES "86")
23+
if(USE_MARCH_NATIVE)
24+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
25+
else()
26+
# Set default march flag to skylake (2015 year) if not using native
27+
if(NOT CMAKE_CXX_FLAGS_RELEASE MATCHES "march=")
28+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=skylake")
29+
endif()
30+
endif()
31+
else()
32+
message(WARNING "The -march option will not be set because the system is not x86 or x64.")
33+
endif()
34+
35+
# Check for LTO support
36+
include(CheckCXXCompilerFlag)
37+
38+
check_cxx_compiler_flag("-flto" COMPILER_SUPPORTS_LTO)
39+
40+
if(COMPILER_SUPPORTS_LTO)
41+
message(STATUS "Link Time Optimization (LTO) is supported by the compiler.")
42+
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
43+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
44+
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
45+
else()
46+
message(WARNING "Link Time Optimization (LTO) is not supported by the compiler.")
47+
endif()
48+
49+
# Export compile flags to a file
50+
file(WRITE "${CMAKE_BINARY_DIR}/compile_flags.txt" "CXXFLAGS: ${CMAKE_CXX_FLAGS_RELEASE}\n")
51+
file(APPEND "${CMAKE_BINARY_DIR}/compile_flags.txt" "LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}\n")
52+
53+
endif()
554

6-
#add_executable(binlog_json_parser main.cpp mysql_json_parser.cpp)
755
add_library(mysqljsonparse SHARED mysqljsonparse.cpp mysql_json_parser.cpp)
48 Bytes
Binary file not shown.
39.2 KB
Binary file not shown.
-20.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)