CMakeLists.txt 6.75 KB
Newer Older
hnc's avatar
hnc committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# Copyright © 2015 Lénaïc Bagnères, hnc@singularity.fr

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


cmake_minimum_required(VERSION 2.6)


# General C++ flags
	
	# General
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wconversion -Wsign-conversion -Wlogical-op -Wdouble-promotion -std=c++14 -pedantic")
	
	# Release
	if (CMAKE_BUILD_TYPE STREQUAL "")
		set(CMAKE_BUILD_TYPE "Release")
	endif()
	
	# Release flags
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG -march=native -ffast-math")
	
	# Debug flags
	set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g3")


# Get local directory where .cmake are
	set(THOTH_CMAKE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

# hopp
	find_package(hopp REQUIRED)

# SFML SYSTEM AUDIO NETWORK
	message(STATUS "---")
	find_package(thoth_sfml_system PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH REQUIRED)
	message(STATUS "---")
	find_package(thoth_sfml_audio PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH REQUIRED)
	message(STATUS "---")
	find_package(thoth_sfml_network PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH REQUIRED)

# OpenSceneGraph
	message(STATUS "---")
hnc's avatar
hnc committed
52
	find_package(thoth_osg PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)
hnc's avatar
hnc committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111

# OGRE
	message(STATUS "---")
	find_package(thoth_ogre PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)

# SFML
	message(STATUS "---")
	find_package(thoth_sfml_window PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)

# SDL1
	message(STATUS "---")
	find_package(thoth_sdl1 PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)

# SDL2
	message(STATUS "---")
	find_package(thoth_sdl2 PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)
	
# Use OpenSceneGraph or OGRE or SFML or SDL2 or SDL2
	# OpenSceneGraph
	if (NOT THOTH_BACKEND AND THOTH_OSG_FOUND)
		set(THOTH_BACKEND "OSG")
	endif()
	if (THOTH_BACKEND STREQUAL "OSG" AND NOT THOTH_OSG_FOUND)
		message(FATAL_ERROR "OSG can not used as back end")
	endif()
	# OGRE
	if (NOT THOTH_BACKEND AND THOTH_OGRE_FOUND)
		set(THOTH_BACKEND "OGRE")
	endif()
	if (THOTH_BACKEND STREQUAL "OGRE" AND NOT THOTH_OGRE_FOUND)
		message(FATAL_ERROR "OGRE can not used as back end")
	endif()
	# SFML
	if (NOT THOTH_BACKEND AND THOTH_SFML_WINDOW_FOUND)
		set(THOTH_BACKEND "SFML")
	endif()
	if (THOTH_BACKEND STREQUAL "SFML" AND NOT THOTH_SFML_WINDOW_FOUND)
		message(FATAL_ERROR "SFML can not used as back end")
	endif()
	# SDL2
	if (NOT THOTH_BACKEND AND THOTH_SDL2_FOUND)
		set(THOTH_BACKEND "SDL2")
	endif()
	if (THOTH_BACKEND STREQUAL "SDL2" AND NOT THOTH_SDL2_FOUND)
		message(FATAL_ERROR "SDL2 can not used as back end")
	endif()
	# SDL1
	if (NOT THOTH_BACKEND AND THOTH_SDL1_FOUND)
		set(THOTH_BACKEND "SDL1")
	endif()
	if (THOTH_BACKEND STREQUAL "SDL1" AND NOT THOTH_SDL1_FOUND)
		message(FATAL_ERROR "SDL1 can not used as back end")
	endif()
	# ERROR
	if (NOT THOTH_BACKEND)
		message(FATAL_ERROR "No back end available")
	endif()
	message(STATUS "---")
	message (STATUS "Thōth uses ${THOTH_BACKEND} as back end")
hnc's avatar
hnc committed
112
	add_definitions("-DTHOTH_BACKEND_${THOTH_BACKEND}")
hnc's avatar
hnc committed
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181

# Thōth X11, Cocoa and d2d1
	message(STATUS "---")
	find_package(thoth_x11 PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)
	find_package(thoth_cocoa PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)
	find_package(thoth_d2d1 PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)

# Thōth media
	message(STATUS "---")
	find_package(thoth_media PATHS "${THOTH_CMAKE_PATH}" NO_DEFAULT_PATH)

# Thōth
	message(STATUS "---")
	set(thoth_INCLUDE "./include")
	include_directories("${thoth_INCLUDE}")
	message(STATUS "Include Thōth = ${thoth_INCLUDE}")


# Compiler log
	message(STATUS "---")
	message(STATUS "C++ compiler = ${CMAKE_CXX_COMPILER}")
	message(STATUS "C++ flags    = ${CMAKE_CXX_FLAGS}")
	message(STATUS "Build type   = ${CMAKE_BUILD_TYPE}")


# Tests
	
	message(STATUS "---")
	
	# Tests
	if (DISABLE_TESTS)
		
		message(STATUS "Tests are disabled")
		
	else()
		
		enable_testing()
		
		file(GLOB_RECURSE tests tests/*.cpp)
		
		foreach(test_source ${tests})
		
			# Get test name and source
			string(REPLACE ".cpp" "" test_name ${test_source})
			string(REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/tests/" "test__" test_name ${test_name})
			string(REPLACE "/" "_" test_name ${test_name})
			
			message(STATUS "Add test ${test_name}")
			
			add_executable(${test_name} "${test_source}")
			add_test(${test_name} "${test_name}")
			
		endforeach()
		
	endif()


# Doxygen
	message(STATUS "---")
	file(MAKE_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/build/doxygen")
	set(DOXYGEN_WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include")
	find_package(hopp_doxygen)


# Install
	# .hpp
	install(DIRECTORY include/ DESTINATION include FILES_MATCHING PATTERN "*.hpp")
	# .cmake
	install(FILES cmake/thoth-config.cmake DESTINATION lib/thoth)
hnc's avatar
hnc committed
182 183
	install(FILES cmake/thoth_cocoa-config.cmake DESTINATION lib/thoth_cocoa)
	install(FILES cmake/thoth_d2d1-config.cmake DESTINATION lib/thoth_d2d1)
hnc's avatar
hnc committed
184 185
	install(FILES cmake/thoth_media-config.cmake DESTINATION lib/thoth_media)
	install(FILES cmake/thoth_ogre-config.cmake DESTINATION lib/thoth_ogre)
hnc's avatar
hnc committed
186 187 188 189 190 191 192 193
	install(FILES cmake/thoth_osg-config.cmake DESTINATION lib/thoth_osg)
	install(FILES cmake/thoth_sdl1-config.cmake DESTINATION lib/thoth_sdl1)
	install(FILES cmake/thoth_sdl2-config.cmake DESTINATION lib/thoth_sdl2)
	install(FILES cmake/thoth_sfml_audio-config.cmake DESTINATION lib/thoth_sfml_audio)
	install(FILES cmake/thoth_sfml_network-config.cmake DESTINATION lib/thoth_sfml_network)
	install(FILES cmake/thoth_sfml_system-config.cmake DESTINATION lib/thoth_sfml_system)
	install(FILES cmake/thoth_sfml_window-config.cmake DESTINATION lib/thoth_sfml_window)
	install(FILES cmake/thoth_x11-config.cmake DESTINATION lib/thoth_x11)
hnc's avatar
hnc committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
	# media
	install(DIRECTORY share/thoth DESTINATION share)
	# Doxygen
	install(DIRECTORY build/doxygen DESTINATION share/thoth)


# Little help
	message(STATUS "---")
	message(STATUS "You can execute:")
	message(STATUS "    make         # To compile executables and tests")
	message(STATUS "    make test    # To execute tests")
	message(STATUS "    make install # To install library, include and CMake module")
	message(STATUS "                 # If you need root access:")
	message(STATUS "                 #     sudo make install")
	message(STATUS "                 #     su -c \"make install\"")
	if (DOXYGEN_FOUND AND DOXYGEN_WORKING_DIRECTORY AND THOTH_DOXYFILE)
		message(STATUS "    make doxygen # To generate the API documentation with Doxygen")
	endif()