Skip to content

Commit

Permalink
Merge pull request #8 from kazuki0824/fix/cleanup-cmake
Browse files Browse the repository at this point in the history
Fix/cleanup cmake
  • Loading branch information
tsukumijima authored Feb 13, 2024
2 parents de123ac + 797d94c commit 687cc44
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)

# Higher than 3.21
if(CMAKE_VERSION VERSION_GREATER 3.21)
cmake_policy(SET CMP0128 NEW)
cmake_policy(SET CMP0128 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER 3.1)
cmake_policy(SET CMP0054 NEW)
if(CMAKE_VERSION VERSION_GREATER 3.15)
cmake_policy(SET CMP0091 NEW)
endif()
cmake_policy(SET CMP0054 NEW)
cmake_policy(SET CMP0063 NEW)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
set(CMAKE_CONFIGURATION_TYPES "Debug;Release" CACHE INTERNAL "limit build types" FORCE)
Expand All @@ -32,7 +33,7 @@ if(WIN32)
option(USE_UNICODE "enable unicode support" ON)
endif()
option(USE_AVX2 "enable AVX2" OFF)
if(NOT WIN32)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "(ARM|ARM64|AARCH64)")
option(USE_NEON "enable NEON" OFF)
endif()

Expand Down Expand Up @@ -75,46 +76,37 @@ set(ARIBB25_VERSION_STRING ${ARIBB25_VERSION_NUMBER})
# ---------- define flags ----------

if(CMAKE_C_COMPILER_ID MATCHES "(GNU|Clang)")
set(CMAKE_C_FLAGS "-Wall")
set(CMAKE_C_FLAGS_DEBUG "-O2 -g")
set(CMAKE_C_FLAGS_RELEASE "-O2")
set(CMAKE_CXX_FLAGS "-Wall")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -g")
set(CMAKE_CXX_FLAGS_RELEASE "-O3")
set(CMAKE_SHARED_LINKER_FLAGS "-fvisibility=hidden")
set(CMAKE_C_VISIBILITY_PRESET "hidden")
set(CMAKE_CXX_VISIBILITY_PRESET "hidden")

if(UNIX AND NOT CYGWIN)
include(ElfInterp)
set(CMAKE_C_FLAGS "-fPIC ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-fPIC ${CMAKE_CXX_FLAGS}")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
if(NOT APPLE)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-eshow_version")
add_link_options("-Wl,-eshow_version")
endif()
else(MINGW)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--enable-stdcall-fixup -static-libgcc")
add_link_options("-Wl,--enable-stdcall-fixup" "-static-libgcc")
endif()

if(MINGW AND USE_UNICODE)
set(CMAKE_C_FLAGS "-municode ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-municode ${CMAKE_CXX_FLAGS}")
add_link_options("-municode")
endif()

if(USE_AVX2)
set(CMAKE_C_FLAGS "-mavx2 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-mavx2 ${CMAKE_CXX_FLAGS}")
add_compile_options("-mavx2")
endif()
if(USE_NEON)
set(CMAKE_C_FLAGS "-mfpu=neon ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-mfpu=neon ${CMAKE_CXX_FLAGS}")
add_compile_options("-mfpu=neon")
endif()
elseif(CMAKE_C_COMPILER_ID MATCHES "MSVC")
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_SUPPRESS_REGENERATION TRUE)
add_compile_options("/utf-8")

if(USE_AVX2)
add_definitions("-DENABLE_MULTI2_SIMD")
set(CMAKE_C_FLAGS "/arch:AVX2 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "/arch:AVX2 ${CMAKE_CXX_FLAGS}")
add_compile_options("/arch:AVX2")
endif()
endif()

Expand All @@ -135,10 +127,10 @@ link_directories(${PCSC_LIBRARY_DIRS})

# ---------- libaribb1 ----------

if(WIN32)
add_library(aribb1-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.c aribb25/multi2_simd.c aribb25/ts_section_parser.c aribb25/version_b1.c)
if(WIN32 AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "(ARM|ARM64|AARCH64)")
add_library(aribb1-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.c aribb25/multi2_simd.c aribb25/ts_section_parser.c aribb25/version_b1.c)
else()
add_library(aribb1-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.cc aribb25/ts_section_parser.c aribb25/version_b1.c)
add_library(aribb1-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.cc aribb25/ts_section_parser.c aribb25/version_b1.c)
endif()
set_target_properties(aribb1-objlib PROPERTIES COMPILE_DEFINITIONS ARIBB1_DLL)
target_compile_definitions(aribb1-objlib PRIVATE ENABLE_ARIB_STD_B1)
Expand Down Expand Up @@ -183,10 +175,10 @@ configure_file(aribb25/version_b1.rc.in version_b1.rc @ONLY)

# ---------- libaribb25 ----------

if(WIN32)
add_library(aribb25-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.c aribb25/multi2_simd.c aribb25/ts_section_parser.c aribb25/version_b25.c)
if(WIN32 AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "(ARM|ARM64|AARCH64)")
add_library(aribb25-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.c aribb25/multi2_simd.c aribb25/ts_section_parser.c aribb25/version_b25.c)
else()
add_library(aribb25-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.cc aribb25/ts_section_parser.c aribb25/version_b25.c)
add_library(aribb25-objlib OBJECT aribb25/arib_std_b25.c aribb25/b_cas_card.c aribb25/multi2.cc aribb25/ts_section_parser.c aribb25/version_b25.c)
endif()
set_target_properties(aribb25-objlib PROPERTIES COMPILE_DEFINITIONS ARIBB25_DLL)

Expand Down

0 comments on commit 687cc44

Please sign in to comment.