CMake Lists
CMake Lists
eu >
# Copyright (C) 2009-2023 Robin Stuart <[email protected]>
# vim: set ts=4 sw=4 et :
cmake_minimum_required(VERSION 3.5)
project(zint-package)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(ZINT_VERSION_MAJOR 2)
set(ZINT_VERSION_MINOR 13)
set(ZINT_VERSION_RELEASE 0)
set(ZINT_VERSION_BUILD 0) # Set to 0 before release, set to 9 after release
set(ZINT_VERSION "${ZINT_VERSION_MAJOR}.${ZINT_VERSION_MINOR}.$
{ZINT_VERSION_RELEASE}.${ZINT_VERSION_BUILD}")
add_definitions(-DZINT_VERSION=\"${ZINT_VERSION}\")
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")
include(SetPaths.cmake)
include(CheckCXXCompilerFlag)
include(CheckFunctionExists)
check_cxx_compiler_flag("-Wextra" CXX_COMPILER_FLAG_WEXTRA)
if(CXX_COMPILER_FLAG_WEXTRA)
add_compile_options("-Wextra")
endif()
check_cxx_compiler_flag("-Wpedantic" CXX_COMPILER_FLAG_WPEDANTIC)
if(CXX_COMPILER_FLAG_WPEDANTIC)
add_compile_options("-Wpedantic")
endif()
endif()
if(ZINT_DEBUG)
check_cxx_compiler_flag("-g" CXX_COMPILER_FLAG_G)
if(CXX_COMPILER_FLAG_G)
add_compile_options("-g")
endif()
endif()
if(ZINT_NOOPT)
check_cxx_compiler_flag("-O0" CXX_COMPILER_FLAG_O0)
if(CXX_COMPILER_FLAG_O0)
add_compile_options("-O0")
endif()
endif()
if(ZINT_SANITIZE)
if(MSVC)
if(MSVC_VERSION GREATER_EQUAL 1920)
add_compile_options(-fsanitize=address)
message(STATUS "ZINT_SANITIZE: setting -fsanitize=address for MSVC
2019")
else()
message(STATUS "ZINT_SANITIZE: ignoring for MSVC < 2019")
endif()
else()
set(SANITIZERS address undefined)
foreach(sanitizer IN ITEMS ${SANITIZERS})
set(CMAKE_REQUIRED_LIBRARIES -fsanitize=${sanitizer})
check_cxx_compiler_flag(-fsanitize=${sanitizer}
CXX_COMPILER_FLAG_FSANITIZE_${sanitizer})
if(CXX_COMPILER_FLAG_FSANITIZE_${sanitizer})
add_compile_options(-fsanitize=${sanitizer})
link_libraries(-fsanitize=${sanitizer})
endif()
unset(CMAKE_REQUIRED_LIBRARIES)
endforeach()
if(ZINT_TEST)
enable_testing()
endif()
if(ZINT_COVERAGE)
set(CMAKE_REQUIRED_LIBRARIES -fprofile-arcs)
check_cxx_compiler_flag(--coverage CXX_COMPILER_FLAG_COVERAGE)
unset(CMAKE_REQUIRED_LIBRARIES)
if(CXX_COMPILER_FLAG_COVERAGE)
add_compile_options(--coverage)
link_libraries(-fprofile-arcs)
check_cxx_compiler_flag(-O0 CXX_COMPILER_FLAG_O0)
if(CXX_COMPILER_FLAG_O0)
add_compile_options(-O0)
endif()
endif()
endif()
if(APPLE)
if(UNIVERSAL) # TODO: make universal binary
if(NOT ZINT_HAS_BEEN_RUN_BEFORE)
if(EXISTS /Developer/SDKs/MacOSX10.5.sdk OR EXISTS
/SDKs/MacOSX10.5.sdk)
set(CMAKE_OSX_ARCHITECTURES "ppc;i386;ppc64;x86_64" CACHE STRING
"Build architectures for OSX" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden
-Wl -single_module " CACHE STRING
"Flags used by the compiler during all build types." FORCE)
elseif(EXISTS /Developer/SDKs/MacOSX10.4u.sdk OR EXISTS
/SDKs/MacOSX10.4u.sdk)
set(CMAKE_OSX_ARCHITECTURES "ppc;i386" CACHE STRING "Build
architectures for OSX" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility-inlines-hidden
-Wl -single_module " CACHE STRING
"Flags used by the compiler during all build types." FORCE)
endif()
message("Build architectures for OSX:${CMAKE_OSX_ARCHITECTURES}")
endif()
else()
set(CMAKE_OSX_SYSROOT "/")
endif()
endif()
check_function_exists(getopt HAVE_GETOPT)
if(NOT HAVE_GETOPT)
add_subdirectory(getopt)
endif()
add_subdirectory(backend)
if(ZINT_FRONTEND)
add_subdirectory(frontend)
endif()
if(NOT ZINT_USE_QT)
message(STATUS "Qt support was disabled for this build")
elseif(ZINT_QT6 OR ($ENV{CMAKE_PREFIX_PATH} MATCHES "6[.][0-9][.][0-9]"))
set(USE_QT6 TRUE)
message(STATUS "Using Qt6")
cmake_policy(SET CMP0012 NEW) # Recognize constants in if()
cmake_policy(SET CMP0072 NEW) # Choose OpenGL over legacy GL
find_package(Qt6Widgets)
find_package(Qt6Gui)
find_package(Qt6UiTools)
find_package(Qt6Svg)
if(ZINT_UNINSTALL)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()
# This needs to be run very last so other parts of the scripts can take
# advantage of this.
if(NOT ZINT_HAS_BEEN_RUN_BEFORE)
set(ZINT_HAS_BEEN_RUN_BEFORE 1 CACHE INTERNAL
"Flag to track whether this is the first time running CMake or if CMake has
been configured before")
endif()