# 设置编译选项
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

# 设置可执行文件的输出地址
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/toolkits)

# 下面设置tools的编译命令 首先设置一个宏
macro(add_tools name)
	# 添加可执行程序名称
	add_executable(${name} ${name}.cpp)
	# 设置安装后的动态库调用地址
	set_target_properties(${name} PROPERTIES INSTALL_RPATH /usr/local/lib)
	# 链接动态库
	target_link_libraries(${name} PUBLIC magtess)
	# 将可执行程序安装到bin
	install(TARGETS ${name} RUNTIME DESTINATION sbin)
endmacro()

# 添加tools
add_tools(tessbx)
add_tools(tessby)
add_tools(tessbz)
add_tools(tessutil_combine_grids)
add_tools(tessutil_gradient_calculator)

if(${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_HOST_SYSTEM_NAME} STREQUAL "Darwin")
	# 添加可执行程序名称
	add_executable(tessutil_magnetize_model tessutil_magnetize_model.c)
	# 设置安装后的动态库调用地址
	set_target_properties(tessutil_magnetize_model PROPERTIES INSTALL_RPATH /usr/local/lib)
	# 链接动态库
	target_link_libraries(tessutil_magnetize_model PUBLIC magtess)
	# 将可执行程序安装到bin
	install(TARGETS tessutil_magnetize_model RUNTIME DESTINATION sbin)
endif()
