# Set the minimum required version of cmake for a project.
cmake_minimum_required (VERSION 2.8.0)

# Set a name for the entire project.
project (zbk-tiles)

IF(UNIX)
	# C++0x is the unofficial name of the planned new standard for the C++ programming language.
	# --include is GCCs alternative to Visual Studios ForcedIncludeFiles.
	set (CMAKE_CXX_FLAGS "-std=c++0x -fopenmp --include ${PROJECT_SOURCE_DIR}/LocalZbk.h")
	IF (EXISTS /etc/release-gentoo)
		set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -nopie")
	ENDIF(EXISTS /etc/release-gentoo)
	# Otherwise we run into problems using "/usr/include/stdlib.h"
	add_definitions (-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)
	set (CMAKE_BUILD_TYPE Release)
ENDIF(UNIX)

# Add subdirectories of the libraries to the build.
add_subdirectory (qtils)
add_subdirectory (bass)
add_subdirectory (croupier)

# Specify source files for the 'zbk-tiles' binary.
# Note: GLOB will generate a list of all files that match the globbing expressions and store it into the variable.
file (GLOB_RECURSE ZBK_TILES_SRCS
)
set (ZBK_TILES_SRCS ${ZBK_TILES_SRCS}
	zbk-tiles.cpp
)

set (ZBK_TILING_SRCS ${ZBK_TILING_SRCS}
	zbk-tiling.cpp
)

# Add include directories to the build.
include_directories (qtils)
include_directories (bass)
include_directories (croupier)

# Define executable and libraries.
set (ZBK_TILES_BIN zbk-tiles)
set (ZBK_TILING_BIN zbk-tiling)
set (ZBK_LIBS Qtils Bass Croupier)

# Add an executable to the project using the specified source files.
add_executable (${ZBK_TILES_BIN} ${ZBK_TILES_SRCS}) 
add_executable (${ZBK_TILING_BIN} ${ZBK_TILING_SRCS}) 

# Link a target to given libraries.
target_link_libraries (${ZBK_TILES_BIN} Bass Qtils Croupier)
target_link_libraries (${ZBK_TILING_BIN} Croupier Bass Qtils)

# Relax PaX for debug.
IF (EXISTS /etc/release-gentoo)
	ADD_CUSTOM_COMMAND (TARGET ${ZBK_TILES_BIN} POST_BUILD COMMAND /sbin/paxctl -m ${ZBK_TILES_BIN})
	ADD_CUSTOM_COMMAND (TARGET ${ZBK_TILING_BIN} POST_BUILD COMMAND /sbin/paxctl -m ${ZBK_TILING_BIN})
ENDIF(EXISTS /etc/release-gentoo)

# Specify rules to run at install time.
install (TARGETS ${ZBK_TILES_BIN} RUNTIME DESTINATION ../bin)
install (TARGETS ${ZBK_TILING_BIN} RUNTIME DESTINATION ../bin)

