-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
96 lines (86 loc) · 4.55 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
cmake_minimum_required(VERSION 3.15)
# mkdir out
# cd out
# cmake .. -G "Visual Studio 17 2022"
# obj2buf.sln
project("obj2buf" DESCRIPTION "Wavefront .obj to packed buffer")
include(CheckIPOSupported)
check_ipo_supported(RESULT hasLTO)
if (MSVC)
# We build Release with the /MD (DLL) option instead of CMake's default /MT (static runtime)
# Note: the disabled warnings are: C4576 C99 type compound literal; C4201 anonymous struct/union
# Note: the regex is to remove CMake's own settings for exception handling (EH), warning level (W) and RTTI (GR)
# TODO: any better way of setting these?
string(REGEX REPLACE "\/EH[a-z]+|\/W[0-4]|\/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "\/W[0-4]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W4 /WX /wd4576 /wd4201 /D_HAS_EXCEPTIONS=0 /MP /D_CRT_SECURE_NO_WARNINGS")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} /EHs-c- /GR-")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /Od /MDd /wd4189")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /O2 /Ot /Oi /MD /GS- /Gy")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /OPT:REF /OPT:ICF")
if (hasLTO)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /GL")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /INCREMENTAL:NO /LTCG")
endif()
else()
# TODO: the generated Xcode project is nonsense, with these flags being ignored and any old crap being compilable
# (e.g. Cmake is inserting -Wno-float-conversion plus others, so -Werror never gets flagged)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "ppc64|powerpc")
# We're on one of my own machines here (no one has Power) so we can apply a tune
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mtune=native")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS} -fno-exceptions -fno-rtti")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g -D_DEBUG=1 -Wno-unused")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -g0")
if (hasLTO)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -flto")
endif()
if (EMSCRIPTEN)
# And for ease-of-use we build Wasm all in one file (which makes it easier to test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msimd128")
set(CMAKE_EXECUTABLE_SUFFIX ".html")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -s SINGLE_FILE=1")
endif()
if(CMAKE_GENERATOR STREQUAL Xcode)
# $(ARCHS_STANDARD) resolves to "" outside of Xcode so compilation fails
set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD)")
endif()
endif()
file(GLOB INCS "inc/*.h")
file(GLOB SRCS "src/*.cpp" "src/*.c")
set(SRCS ${SRCS}
# "src/meshopt/allocator.cpp"
# "src/meshopt/clusterizer.cpp"
# "src/meshopt/indexcodec.cpp"
"src/meshopt/indexgenerator.cpp"
# "src/meshopt/overdrawanalyzer.cpp"
"src/meshopt/overdrawoptimizer.cpp"
# "src/meshopt/quantization.cpp"
# "src/meshopt/simplifier.cpp"
# "src/meshopt/spatialorder.cpp"
# "src/meshopt/stripifier.cpp"
# "src/meshopt/vcacheanalyzer.cpp"
"src/meshopt/vcacheoptimizer.cpp"
# "src/meshopt/vertexcodec.cpp"
# "src/meshopt/vertexfilter.cpp"
# "src/meshopt/vfetchanalyzer.cpp"
"src/meshopt/vfetchoptimizer.cpp"
)
include_directories("inc")
source_group(TREE "${PROJECT_SOURCE_DIR}/inc" PREFIX "Headers" FILES ${INCS})
source_group(TREE "${PROJECT_SOURCE_DIR}/src" PREFIX "Sources" FILES ${SRCS})
add_executable(${CMAKE_PROJECT_NAME} ${INCS} ${SRCS})
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY CXX_STANDARD 11)
# Make this a little nicer in VS
# (Note: the working dir only works from a generated solution, not as a folder in VS)
set_property(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT ${CMAKE_PROJECT_NAME})
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/dat")
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY VS_DEBUGGER_COMMAND_ARGUMENTS "-c 8115547B cube.obj out.inc")
# Add some scheme defaults for an Xcode generated solution (note we chose CMake's own vars over, e.g., $PROJECT_DIR)
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY XCODE_GENERATE_SCHEME TRUE)
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY XCODE_SCHEME_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/dat")
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY XCODE_SCHEME_ARGUMENTS "-c 8115547B cube.obj out.inc")
# And save some time only building the native arch for debug
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] YES)