cmake_minimum_required(VERSION 2.8)
project(lsms11_sdk)

#set(CMAKE_PROJECT_NAME lsms11_sdk)
#project(${CMAKE_PROJECT_NAME} C)

IF (APPLE)
	set(PKCS11_API_PATH  liblsms11x.dylib)
ELSEIF (UNIX)
	set(PKCS11_API_PATH  liblsms11x.so)
ELSEIF (WIN32)
	set(PKCS11_API_PATH  lsms11x)
ENDIF (APPLE)

set(USER_PIN  01234567)

include(CTest)

include_directories(
	${CMAKE_CURRENT_SOURCE_DIR}/include 
	${CMAKE_CURRENT_SOURCE_DIR}/common
)

macro(compile_tool)
        add_executable(${ARGV0} 
		${ARGN}
		${CMAKE_CURRENT_SOURCE_DIR}/common/test_common.h
		${CMAKE_CURRENT_SOURCE_DIR}/common/test_common.c
		${CMAKE_CURRENT_SOURCE_DIR}/common/getopt.c
	)	
	if (UNIX)
		target_link_libraries(${ARGV0} dl pthread)
	endif (UNIX)
endmacro(compile_tool)

macro(compile_test)
	compile_tool(${ARGN})
	if (PKCS11_API_PATH)
		# Запуск теста для библиотеки PKCS11_API_PATH
		add_test(hw_${ARGV0} 
			${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${ARGV0}
			-api ${PKCS11_API_PATH} -user_pin ${USER_PIN}
		)
	endif (PKCS11_API_PATH)
endmacro(compile_test)

compile_tool(c_wait_for_slot_event c_wait_for_slot_event.c)
compile_tool(bug_reports bug_reports.c)

compile_test(info info.c)
compile_test(cko_certificate cko_certificate.c)
compile_test(cko_data cko_data.c)
compile_test(ckm_gostr3411 ckm_gostr3411.c)
compile_test(ckm_gostr3411_hmac ckm_gostr3411_hmac.c)
compile_test(ckm_gost28147_key_gen ckm_gost28147_key_gen.c)
compile_test(ckm_gost28147 ckm_gost28147.c)
compile_test(ckm_gost28147_ecb ckm_gost28147_ecb.c)
compile_test(ckm_gost28147_ecb_mac_wrap ckm_gost28147_ecb_mac_wrap.c)
compile_test(ckm_gost28147_cnt ckm_gost28147_cnt.c)
compile_test(ckm_gost28147_cbc ckm_gost28147_cbc.c)
compile_test(ckm_gost28147_mac ckm_gost28147_mac.c)
compile_test(ckm_gost28147_key_wrap ckm_gost28147_key_wrap.c)
compile_test(ckm_gostr3410_key_pair_gen ckm_gostr3410_key_pair_gen.c)
compile_test(ckm_gostr3410 ckm_gostr3410.c)
compile_test(ckm_gostr3410_key_derive ckm_gostr3410_key_derive.c)
compile_test(ckm_gostr3410_key_wrap ckm_gostr3410_key_wrap.c)
compile_test(ckm_gostr3410_with_gostr3411 ckm_gostr3410_with_gostr3411.c)
compile_test(ckm_tls_gost_prf ckm_tls_gost_prf.c)
compile_test(ckm_tls_gost_pre_master_key_gen ckm_tls_gost_pre_master_key_gen.c)
compile_test(ckm_tls_gost_master_key_derive ckm_tls_gost_master_key_derive.c)
compile_test(ckm_tls_gost_key_and_mac_derive ckm_tls_gost_key_and_mac_derive.c)
compile_test(ckm_pkcs5_pbkd2 ckm_pkcs5_pbkd2.c)
compile_test(ckm_pba_gostr3411_with_gostr3411_hmac ckm_pba_gostr3411_with_gostr3411_hmac.c)
compile_test(ckm_gost28147_pkcs8_key_wrap ckm_gost28147_pkcs8_key_wrap.c)
compile_test(create_obj create_obj.c)
compile_test(pin_and_flags pin_and_flags.c)
compile_test(c_init_token c_init_token.c)
compile_test(format format.c)
compile_test(login login.c)
compile_test(threadmkobj threadmkobj.c)
