# Orthanc - A Lightweight, RESTful DICOM Store
# Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
# Department, University Hospital of Liege, Belgium
# Copyright (C) 2017-2023 Osimis S.A., Belgium
# Copyright (C) 2024-2025 Orthanc Team SRL, Belgium
# Copyright (C) 2021-2025 Sebastien Jodogne, ICTEAM UCLouvain, Belgium
#
# This program is free software: you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# as published by the Free Software Foundation, either version 3 of
# the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program. If not, see
# .
# This file sets all the compiler-related flags
if (${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
# Since Orthanc 1.12.7 that allows CMake 4.0, builds for macOS
# require the C++ standard to be explicitly set to C++11. Do *not*
# do this on GNU/Linux, as third-party system libraries could have
# been compiled with higher versions of the C++ standard.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
# Save the current compiler flags to the cache every time cmake configures the project
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" CACHE STRING "compiler flags" FORCE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" CACHE STRING "compiler flags" FORCE)
include(CheckLibraryExists)
if ((CMAKE_CROSSCOMPILING AND NOT
"${CMAKE_SYSTEM_VERSION}" STREQUAL "CrossToolNg") OR
"${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
# Cross-compilation necessarily implies standalone and static build
SET(STATIC_BUILD ON)
SET(STANDALONE_BUILD ON)
endif()
if ("${CMAKE_SYSTEM_VERSION}" STREQUAL "LinuxStandardBase")
# Cache the environment variables "LSB_CC" and "LSB_CXX" for further
# use by "ExternalProject" in CMake
SET(CMAKE_LSB_CC $ENV{LSB_CC} CACHE STRING "")
SET(CMAKE_LSB_CXX $ENV{LSB_CXX} CACHE STRING "")
# This is necessary to build "Orthanc mainline - Framework LSB
# Release" on "buildbot-worker-debian11"
set(LSB_PTHREAD_NONSHARED "${LSB_PATH}/lib64-${LSB_TARGET_VERSION}/libpthread_nonshared.a")
if (EXISTS ${LSB_PTHREAD_NONSHARED})
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LSB_PTHREAD_NONSHARED}")
endif()
endif()
if (CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-long-long")
# --std=c99 makes libcurl not to compile
# -pedantic gives a lot of warnings on OpenSSL
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -Wno-variadic-macros")
if (CMAKE_CROSSCOMPILING)
# http://stackoverflow.com/a/3543845/881731
set(CMAKE_RC_COMPILE_OBJECT " -O coff -I