project (osl CXX)
cmake_minimum_required (VERSION 2.8)
set (CMAKE_VERBOSE_MAKEFILE on)

ENABLE_TESTING()

if (UNIX)
  set (CMAKE_CXX_FLAGS "-Wall")
  set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG")
  set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG")
  add_definitions(-march=native -DBOOST_FILESYSTEM_VERSION=2) 
endif()

if(MINGW)
  set (CMAKE_CXX_FLAGS "-Wall -D_MT -mthreads -mwin32 -msse2 -static-libgcc -static-libstdc++ -DWIN32_LEAN_AND_MEAN")
  set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g -DDEBUG")
  set (CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -march=pentium4 -funroll-loops -funswitch-loops -fpeel-loops --param large-function-growth=48000 --param inline-unit-growth=8000 --param max-inline-insns-single=8000 -fomit-frame-pointer")
  add_definitions(-DOSL_SMP=1 -DOSL_DFPN_SMP_SEARCH -DMORE_CHECKMATE_IF_CAPTURE_MAJOR -DBOOST_FILESYSTEM_VERSION=2 -DBOOST_THREAD_USE_LIB=1 -DUSE_BOOST_POOL_ALLOCATOR=1 -D_WIN32_WINNT=0x0500)
  set (BOOST_ROOT "$ENV{HOME}/local/src/boost_1_46_1/")
endif(MINGW)

add_definitions(-DOSL_HOME="${CMAKE_CURRENT_SOURCE_DIR}" -DUSE_TCMALLOC=0 -D_REENTRANT)

include_directories ("${PROJECT_SOURCE_DIR}/include")

## Pthreads
#find_package (Threads)
#if (Threads_FOUND)
#  message (STATUS "Threads: ${CMAKE_THREAD_LIBS_INIT}")
#else()
#  message (FATAL_ERROR "Threads not found")
#endif()

## Boost thing
#set (BOOST_ROOT "$ENV{HOME}/local/boost_1_36_0_binaries/")
set (Boost_USE_STATIC_LIBS ON)
set (Boost_USE_MULTITHREADED ON)
find_package (Boost 1.46.1)
if (Boost_FOUND)
  include_directories (${Boost_INCLUDE_DIRS})
  message (STATUS ${Boost_INCLUDE_DIRS})
else()
  message (FATAL_ERROR "Boost installation not found")
endif()

## Program SampleCounter
file(GLOB_RECURSE OSL_HEADERS  include/*.h include/*.tcc)
file(GLOB_RECURSE OSL_SRCS     lib/*.cc)
file(GLOB_RECURSE EXCLUDE_SRCS lib/third_party/*.cc lib/ntesuki/*.cc)
list(REMOVE_ITEM OSL_SRCS ${EXCLUDE_SRCS})
#message (STATUS "Headers: ${OSL_HEADERS}")
#message (STATUS "Sources: ${OSL_SRCS}")
#set (SampleAleriUDF_ALL_SRCS ${SampleAleriUDF_HEADERS} ${SampleAleriUDF_SRCS})
add_library (osl-static STATIC ${OSL_SRCS})
SET_TARGET_PROPERTIES(osl-static PROPERTIES OUTPUT_NAME "osl")
SET_TARGET_PROPERTIES(osl-static PROPERTIES PREFIX "lib")
if (UNIX)
  add_library (osl SHARED ${OSL_SRCS})
  target_link_libraries (osl ${CMAKE_THREAD_LIBS_INIT})
endif()

