forked from panzi/VTFLib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
141 lines (112 loc) · 4.53 KB
/
CMakeLists.txt
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
52
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
112
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
cmake_minimum_required(VERSION 2.8)
project(VTFLib)
set(VTFLIB_MAJOR_VERSION 1)
set(VTFLIB_MINOR_VERSION 3)
set(VTFLIB_PATCH_VERSION 2)
set(VTFLIB_NAME VTFLib${VTFLIB_MAJOR_VERSION}${VTFLIB_MINOR_VERSION})
set(VTFLIB_VERSION ${VTFLIB_MAJOR_VERSION}.${VTFLIB_MINOR_VERSION}.${VTFLIB_PATCH_VERSION})
# ---- options ----------------------------------------------------------------
option(USE_NVDXT "(Windows only) VTF creation requires a S3TC implementation.
For this nvDXTLib can be used and has been tested with version 8.31.1127.1645, availible here:
http://developer.nvidia.com/object/dds_utilities_legacy.html" OFF)
option(USE_LIBTXC_DXTN "VTF creation requires a S3TC implementation.
For this libtxc_dxtn can be used, availible here:
http://cgit.freedesktop.org/~mareko/libtxc_dxtn/" ON)
option(BUILD_DOCS "Build doxygen documentation" OFF)
if(USE_NVDXT AND USE_LIBTXC_DXTN)
message(FATAL_ERROR "Cannot use both options USE_NVDXT and USE_LIBTXC_DXTN at once.")
endif()
# ---- dependencies -----------------------------------------------------------
if(USE_LIBTXC_DXTN)
find_path(GL_INCLUDE_DIR GL/gl.h)
find_library(LIBTXC_DXTN_LIBRARY txc_dxtn)
if(NOT(GL_INCLUDE_DIR))
message(FATAL_ERROR "GL/gl.h not found!
Please re-run with -DUSE_LIBTXC_DXTN=OFF if you don't want S3TC support.")
endif()
if(NOT(LIBTXC_DXTN_LIBRARY))
message(FATAL_ERROR "libtxc_dxtn not found!
Please re-run with -DUSE_LIBTXC_DXTN=OFF if you don't want S3TC support.")
endif()
add_definitions(-DUSE_LIBTXC_DXTN)
include_directories(${GL_INCLUDE_DIR})
endif()
# ---- compiler flags ---------------------------------------------------------
if(MSVC)
# Force to always compile with W4
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
endif()
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra -pedantic -Werror -O3")
endif()
if(USE_NVDXT AND ${CMAKE_SYSTEM_NAME} STREQUAL "Windows")
add_definitions(-DUSE_NVDXT)
# TODO: libraries?
endif()
if(UNIX)
# big file support (files > 2GB). makes off_t 64bit even on 32bit platforms and makes fseeko/ftello available.
set(VTFLIB_PC_CFLAGS "-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE")
add_definitions(${VTFLIB_PC_CFLAGS})
endif()
# compiling the library now:
add_definitions(-DVTFLIB_EXPORTS)
# for config.h
include_directories("${PROJECT_BINARY_DIR}/src")
# ---- pkg config -------------------------------------------------------------
# for CMAKE_INSTALL_LIBDIR:
include(GNUInstallDirs)
# from libpng
# Set a variable with CMake code which:
# Creates a symlink from src to dest (if possible) or alternatively
# copies if different.
macro(vtflib_generate_symlink_code CODE SRC DEST WORKING_DIR)
if(WIN32 AND NOT CYGWIN)
set(_vtflib_gsc_message "Copying ${SRC} to ${DEST} if needed")
set(_vtflib_gsc_operation "copy_if_different")
else()
set(_vtflib_gsc_message "Symlinking ${SRC} to ${DEST}")
set(_vtflib_gsc_operation "create_symlink")
endif()
set(${CODE} "
message(STATUS \"${_vtflib_gsc_message}\")
execute_process(COMMAND \${CMAKE_COMMAND} -E ${_vtflib_gsc_operation}
\"${SRC}\" \"${DEST}\" WORKING_DIRECTORY \"${WORKING_DIR}\")
")
endmacro()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/VTFLib.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${VTFLIB_NAME}.pc @ONLY)
vtflib_generate_symlink_code(VTFLIB_PC_INSTALL_CODE
${VTFLIB_NAME}.pc
VTFLib.pc
${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${VTFLIB_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(CODE ${VTFLIB_PC_INSTALL_CODE})
# ---- sub directories --------------------------------------------------------
add_subdirectory(src)
# ---- docs tareget -----------------------------------------------------------
if(BUILD_DOCS)
find_package(Doxygen)
if(NOT DOXYGEN_FOUND)
message(FATAL_ERROR
"Doxygen is needed to build the documentation.")
endif()
configure_file(Doxyfile.in
"${PROJECT_BINARY_DIR}/Doxyfile" @ONLY)
add_custom_target(docs ALL
COMMAND ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile
SOURCES ${PROJECT_BINARY_DIR}/Doxyfile)
endif()
# ---- uninstall target -------------------------------------------------------
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
endif()