Skip to content
Open
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
73 changes: 68 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,53 @@ project(libisyntax)
set(CMAKE_C_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_BUILD_TYPE Debug)
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(aarch64.*|AARCH64.*|arm64.*|ARM64.*)")
set(IS_ARM64 TRUE)
set(ARM_ARCH "arm64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm.*|ARM.*)")
set(IS_ARM TRUE)
set(ARM_ARCH "arm")
endif()
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")

if(CMAKE_SYSTEM_PROCESSOR MATCHES "^(arm|aarch64)")
message(STATUS "Enabling ARM NEON support")
add_compile_options(-mfpu=neon)
if(APPLE AND (IS_ARM OR IS_ARM64))
set(IS_APPLE_SILICON TRUE)
endif()

if(IS_APPLE_SILICON)
message(STATUS "Detected Apple silicon ${ARM_ARCH} architecture")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch ${ARM_ARCH}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch ${ARM_ARCH}")
# Enable NEON for ARM-based Apple Silicon
add_compile_options(-march=armv8.2-a+fp16+simd)
endif()


option(ENABLE_MEMORY_CHECK "Enable memory check with sanitizers (requires DEBUG mode)" OFF)

if(ENABLE_MEMORY_CHECK)
if(NOT CMAKE_BUILD_TYPE MATCHES Debug)
message(FATAL_ERROR "ENABLE_MEMORY_CHECK is only allowed in Debug build mode")
endif()

if(APPLE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address -fno-omit-frame-pointer")
set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
elseif(UNIX AND NOT APPLE) # Linux
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O1 -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Og -g")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -Og -g")
endif()
endif()

message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")



set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}")

include_directories("${CMAKE_SOURCE_DIR}/src")
Expand All @@ -21,6 +59,15 @@ include_directories("${CMAKE_SOURCE_DIR}/src/utils")
include_directories("${CMAKE_SOURCE_DIR}/src/isyntax")
include_directories("${CMAKE_SOURCE_DIR}/src/third_party")


# Add threads library for linux
find_package(Threads REQUIRED)

if(UNIX AND NOT APPLE)
set(LIBRT rt)
endif()


set(LIBISYNTAX_COMMON_SOURCE_FILES
src/libisyntax.c
src/isyntax/isyntax.c
Expand Down Expand Up @@ -49,6 +96,22 @@ add_executable(isyntax_example
${LIBISYNTAX_COMMON_SOURCE_FILES}
)

target_link_libraries(isyntax_example PRIVATE Threads::Threads ${LIBRT})

# Find LibTIFF library
find_package(TIFF REQUIRED)
if (NOT TIFF_FOUND)
message(WARNING "LibTIFF not found")
message(WARNING "Will not compile `isyntax-to-tiff` utility")
else()
include_directories(${TIFF_INCLUDE_DIR})
add_executable(isyntax-to-tiff
src/isyntax_to_tiff.c
${LIBISYNTAX_COMMON_SOURCE_FILES} ${TIFF_LIBRARIES} src/isyntax_to_tiff.c)
target_link_libraries(isyntax-to-tiff PRIVATE ${TIFF_LIBRARIES} Threads::Threads ${LIBRT})
endif()


if (WIN32)
target_link_libraries(libisyntax winmm)
target_link_libraries(isyntax_example winmm)
Expand Down
Loading