###############################################################################
#
#  Build Process for the log4cpp module useable by the GenICam GenApi
#    Author:  Christian Hartinger
#    (c) 2024 by MVTec Software GmbH
#
#  Log4cpp standalone build configuration.
#  The log4cpp binary built here is loaded at runtime by the GenApi 'Log' module.
#  The 'Log' library loads log4cpp at runtime based on its filename. 
#  The name of the log4cpp library is expected with the same suffixes as the Log library.
#  This means if your genicam package contains for example GenApi_MD_VC141_v3_4.dll/libGenApi_gcc48_v3_4.so
#  then the log4cpp library needs to be called log4cpp_MD_VC141_v3_4.dll/liblog4cpp_gcc48_v3_4.so.
#  This is ensured by the variable GENICAM_COMPILER_SUFFIX below in this script. 
#  This also means the mentioned compiler should be used to compile log4cpp for GenApi standalone.
#  Also, for windows the correct version of the MSVC runtime library must be used (MT/MD).
#  There is no guarantee that other compilers will produce a compatible binary!!!
#
#  License: This file is published under the license of the EMVA GenICam  Standard Group.
#  A text file describing the legal terms is included in  your installation as 'GenICam_license.pdf'.
#  If for some reason you are missing  this file please contact the EMVA or visit the website
#  (http:#www.genicam.org) for a full copy.
#
#  THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
#  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
#  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
#  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD  GROUP
#  OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  SPECIAL,
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT  LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT  (INCLUDING NEGLIGENCE OR OTHERWISE)
#  ARISING IN ANY WAY OUT OF THE USE  OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGE.
###############################################################################

cmake_minimum_required(VERSION 3.7)

project(Log4CPP_GenApi VERSION 3.5)

#------------------------------------------------------------------------------
#  Define source
#------------------------------------------------------------------------------
set(SOURCES
    log4cpp/AbortAppender.cpp
    log4cpp/Appender.cpp
    log4cpp/AppenderSkeleton.cpp
    log4cpp/AppendersFactory.cpp
    log4cpp/BasicConfigurator.cpp
    log4cpp/BasicLayout.cpp
    log4cpp/BufferingAppender.cpp
    log4cpp/Category.cpp
    log4cpp/CategoryStream.cpp
    log4cpp/Configurator.cpp
    log4cpp/DllMain.cpp
    log4cpp/DummyThreads.cpp
    log4cpp/FactoryParams.cpp
    log4cpp/FileAppender.cpp
    log4cpp/Filter.cpp
    log4cpp/FixedContextCategory.cpp
    log4cpp/HierarchyMaintainer.cpp
    log4cpp/IdsaAppender.cpp
    log4cpp/LayoutAppender.cpp
    log4cpp/LayoutsFactory.cpp
    log4cpp/LevelEvaluator.cpp
    log4cpp/Localtime.cpp
    log4cpp/LoggingEvent.cpp
    log4cpp/MSThreads.cpp
    log4cpp/NDC.cpp
    log4cpp/NTEventLogAppender.cpp
    log4cpp/OmniThreads.cpp
    log4cpp/OstreamAppender.cpp
    log4cpp/PThreads.cpp
    log4cpp/PassThroughLayout.cpp
    log4cpp/PatternLayout.cpp
    log4cpp/PortabilityImpl.cpp
    log4cpp/Priority.cpp
    log4cpp/Properties.cpp
    log4cpp/PropertyConfigurator.cpp
    log4cpp/PropertyConfiguratorImpl.cpp
    log4cpp/RemoteSyslogAppender.cpp
    log4cpp/RollingFileAppender.cpp
    log4cpp/RTSSUtilities.cpp
    log4cpp/SimpleConfigurator.cpp
    log4cpp/SimpleLayout.cpp
    log4cpp/StringQueueAppender.cpp
    log4cpp/StringUtil.cpp
    log4cpp/SyslogAppender.cpp
    log4cpp/TimeStamp.cpp
    log4cpp/TriggeringEventEvaluatorFactory.cpp
    log4cpp/Win32DebugAppender.cpp
    log4cpp/Utilities.cpp
    log4cpp/Manipulator.cpp
    log4cpp/SmtpAppender.cpp
    log4cpp/Wrapper.cpp
    log4cpp/CategoryAdapter.cpp
    log4cpp/Log4cppAdapter.cpp
)

set(GENICAM_COMPILER_SUFFIX gcc494)

#------------------------------------------------------------------------------
# Build the library
#------------------------------------------------------------------------------
add_library (log4cpp SHARED ${SOURCES})
set_target_properties(log4cpp PROPERTIES OUTPUT_NAME log4cpp_${GENICAM_COMPILER_SUFFIX}_v${PROJECT_VERSION_MAJOR}_${PROJECT_VERSION_MINOR})

set_target_properties(log4cpp PROPERTIES CXX_STANDARD 98)

target_include_directories(log4cpp PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

target_compile_definitions(log4cpp PRIVATE LOG4CPP_HAS_DLL)
target_compile_definitions(log4cpp PRIVATE LOG4CPP_BUILD_DLL)

if (WIN32)
    target_compile_definitions(log4cpp PRIVATE _WINSOCK_DEPRECATED_NO_WARNINGS )

    target_link_libraries (log4cpp ws2_32)
else()
    target_link_libraries (log4cpp pthread)
endif()
