project(cd_utils)
cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0017 OLD)
if (NOT LIBPROJECT)
	find_package(PIP REQUIRED)
	option(LIB "System install" 1)
	option(DEBUG "Build with -g3" 0)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -Wall")
	if (DEBUG)
		set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g3")
	endif()
endif()
if (MINGW)
	find_package(MinGW REQUIRED)
endif()
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${PIP_INCLUDES})
#file(GLOB HDRS_UTILS "*.h")
#file(GLOB CPPS_UTILS "*.cpp")
set(CPPS_UTILS "cdutils_core.cpp" "cdutils_types.cpp" "cdutils_parser.cpp" "cdutils_k.cpp")
set(HDRS_UTILS "cdutils_core.h" "cdutils_types.h" "cdutils_parser.h" "cdutils_k.h" "cdutils_protocol.h")
if (DEFINED ENV{QNX_HOST})
	add_library(${PROJECT_NAME} STATIC ${CPPS_UTILS} ${HDRS_UTILS})
else()
	add_library(${PROJECT_NAME} SHARED ${CPPS_UTILS} ${HDRS_UTILS})
endif()
target_link_libraries(${PROJECT_NAME} ${PIP_LIBRARY})

add_executable(cdutilstest "cdutilstest.cpp" "cdtest.h")
target_link_libraries(cdutilstest ${PIP_LIBRARY} ${PROJECT_NAME})
message(STATUS "Building ${PROJECT_NAME}")
#if (LIBPROJECT)
#	include(SDKMacros)
#	sdk_install("" "${PROJECT_NAME}" "${HDRS_UTILS}")
#else()
	if(LIB)
		if(WIN32)
			set(CMAKE_INSTALL_PREFIX ${MINGW_DIR})
			install(FILES ${HDRS_UTILS} DESTINATION ${MINGW_INCLUDE})
			install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_LIB})
			install(TARGETS ${PROJECT_NAME} DESTINATION ${MINGW_BIN})
		else()
			if(APPLE)
				set(CMAKE_INSTALL_PREFIX /usr/local)
			else()
				set(CMAKE_INSTALL_PREFIX /usr)
			endif()
			install(FILES ${HDRS_UTILS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
			install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
		endif()
		#message(STATUS "Install ${PROJECT_NAME} to system \"${CMAKE_INSTALL_PREFIX}\"")
	else()
		install(TARGETS ${PROJECT_NAME} DESTINATION bin)
		#message(STATUS "Install ${PROJECT_NAME} to local \"bin\"")
	endif()
#endif()
