##
#   Copyright (C) 2004 - 2026 Université de Versailles Saint-Quentin-en-Yvelines (UVSQ)
#
#   This file is part of MAQAO.
#
#  MAQAO 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, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
##

### --- Create the libcounting library --- ###
# List the source files #
FILE(GLOB
   libcounting_files
   libcounting.c
)

# Create the lprof object for DYNAMIC libraries/binaries #
ADD_LIBRARY          (libcounting-obj-dyn       OBJECT ${libcounting_files})
SET_TARGET_PROPERTIES(libcounting-obj-dyn       PROPERTIES COMPILE_FLAGS "${C_DYNAMIC_FLAGS}")

# Create the library #
IF(is_WINDOWS)
	ADD_LIBRARY          (libcounting-lib-static    STATIC $<TARGET_OBJECTS:libcounting-obj-dyn>
	                                                       $<TARGET_OBJECTS:perf-obj-dyn>)
ELSE(is_WINDOWS)
	ADD_LIBRARY          (libcounting-lib-static    STATIC $<TARGET_OBJECTS:libcounting-obj-dyn>
	                                                       $<TARGET_OBJECTS:perf-obj-static>)
ENDIF(is_WINDOWS)
SET_TARGET_PROPERTIES(libcounting-lib-static    PROPERTIES COMPILE_FLAGS "${C_STATIC_FLAGS}")
SET_TARGET_PROPERTIES(libcounting-lib-static    PROPERTIES PREFIX "" OUTPUT_NAME libcounting)


# Create the library #
IF(is_WINDOWS)
	ADD_LIBRARY          (libcounting-lib-dyn     SHARED $<TARGET_OBJECTS:libcounting-obj-dyn>
	                                                     $<TARGET_OBJECTS:perf-obj-dyn>)
ELSE(is_WINDOWS)
	ADD_LIBRARY          (libcounting-lib-dyn     SHARED $<TARGET_OBJECTS:libcounting-obj-dyn>
	                                                     $<TARGET_OBJECTS:perf-obj-static>)
ENDIF(is_WINDOWS)
SET_TARGET_PROPERTIES(libcounting-lib-dyn     PROPERTIES COMPILE_FLAGS "${C_DYNAMIC_FLAGS}")
SET_TARGET_PROPERTIES(libcounting-lib-dyn     PROPERTIES PREFIX "" OUTPUT_NAME libcounting)
TARGET_LINK_LIBRARIES(libcounting-lib-dyn     pthread)
ADD_DEPENDENCIES     (libcounting-lib-dyn     maqao)

# Install the dynamic lprof instrumentation library #
INSTALL(TARGETS libcounting-lib-dyn DESTINATION lib)

FILE(COPY libcounting.h DESTINATION ${INCLUDE_OUTPUT_PATH}/)
