Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compile options #14

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 50 additions & 2 deletions binlog_json_parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,55 @@
cmake_minimum_required(VERSION 3.0)
cmake_minimum_required(VERSION 3.20)

project(binlog_json_parser)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Check if the build type is Release
if(CMAKE_BUILD_TYPE STREQUAL "Release")

# Set optimization level to -O3 for release builds
if(NOT CMAKE_CXX_FLAGS_RELEASE MATCHES "-O")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()

# Option to add march-native for release builds
option(USE_MARCH_NATIVE "Enable -march=native for release builds" OFF)

# Determine the architecture
include(CMakeDetermineSystem)

if(CMAKE_SYSTEM_PROCESSOR MATCHES "86")
if(USE_MARCH_NATIVE)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=native")
else()
# Set default march flag to skylake (2015 year) if not using native
if(NOT CMAKE_CXX_FLAGS_RELEASE MATCHES "march=")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -march=skylake")
endif()
endif()
else()
message(WARNING "The -march option will not be set because the system is not x86 or x64.")
endif()

# Check for LTO support
include(CheckCXXCompilerFlag)

check_cxx_compiler_flag("-flto" COMPILER_SUPPORTS_LTO)

if(COMPILER_SUPPORTS_LTO)
message(STATUS "Link Time Optimization (LTO) is supported by the compiler.")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
else()
message(WARNING "Link Time Optimization (LTO) is not supported by the compiler.")
endif()

# Export compile flags to a file
file(WRITE "${CMAKE_BINARY_DIR}/compile_flags.txt" "CXXFLAGS: ${CMAKE_CXX_FLAGS_RELEASE}\n")
file(APPEND "${CMAKE_BINARY_DIR}/compile_flags.txt" "LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}\n")

endif()

#add_executable(binlog_json_parser main.cpp mysql_json_parser.cpp)
add_library(mysqljsonparse SHARED mysqljsonparse.cpp mysql_json_parser.cpp)
Binary file modified mysql_ch_replicator/pymysqlreplication/libmysqljsonparse.dylib
Binary file not shown.
Binary file modified mysql_ch_replicator/pymysqlreplication/libmysqljsonparse.so
Binary file not shown.
Binary file not shown.
Loading