view cmake/function/MalikaniaDefineExample.cmake @ 188:0cecdadfb5c4

Misc: rework javascript bindings, closes #916 While here, create new test libraries for future unit tests.
author David Demelier <markand@malikania.fr>
date Wed, 24 Oct 2018 21:13:12 +0200
parents 387f6b0a5420
children 0a285d62ace7
line wrap: on
line source

#
# MalikaniaDefineExample.cmake -- CMake build system for malikania
#
# Copyright (c) 2013-2018 David Demelier <markand@malikania.fr>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

include(CMakeParseArguments)

function(malikania_define_example)
	set(singleArgs TARGET)
	set(multiArgs FLAGS LIBRARIES SOURCES)

	cmake_parse_arguments(EXP "" "${singleArgs}" "${multiArgs}" ${ARGN})

	if (NOT EXP_TARGET)
		message(FATAL_ERROR "Missing TARGET parameter")
	elseif (NOT EXP_SOURCES)
		message(FATAL_ERROR "Missing SOURCES parameter")
	endif ()

	add_executable(example-${EXP_TARGET} ${EXP_SOURCES})
	target_link_libraries(example-${EXP_TARGET} ${EXP_LIBRARIES})
	target_compile_definitions(
		example-${EXP_TARGET}
		PRIVATE
			CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}"
			CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}"
			${EXP_FLAGS}
	)
	set_target_properties(
		example-${EXP_TARGET}
		PROPERTIES
			RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
	)
	foreach (c ${CMAKE_CONFIGURATION_TYPES})
		string(TOUPPER ${c} cu)
		set_target_properties(
			example-${EXP_TARGET}
			PROPERTIES
				RUNTIME_OUTPUT_DIRECTORY_${cu} ${CMAKE_BINARY_DIR}/bin/${c}
		)
	endforeach ()
endfunction()