forked from SanderMertens/flecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
85 lines (64 loc) · 2.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
cmake_minimum_required(VERSION 3.1)
cmake_policy(SET CMP0063 NEW)
project(flecs LANGUAGES C)
option(FLECS_STATIC_LIBS "Build static flecs lib" ON)
option(FLECS_PIC "Compile static flecs lib with position-independent-code (PIC)" ON)
option(FLECS_SHARED_LIBS "Build shared flecs lib" ON)
option(FLECS_DEVELOPER_WARNINGS "Enable more warnings" OFF)
if(NOT FLECS_STATIC_LIBS AND NOT FLECS_SHARED_LIBS)
message(FATAL_ERROR "At least one of FLECS_STATIC_LIBS or FLECS_SHARED_LIBS options must be enabled")
endif()
# include utilities for compiler options and warnings
include(cmake/target_default_compile_warnings.cmake)
include(cmake/target_default_compile_options.cmake)
# collect all include and source files
# (use the manual list to improve ide support)
file(GLOB_RECURSE INC include/*.h include/*.hpp)
file(GLOB_RECURSE SRC src/*.c)
set(FLECS_TARGETS "")
# build the shared library
if(FLECS_SHARED_LIBS)
add_library(flecs SHARED ${INC} ${SRC})
add_library(flecs::flecs ALIAS flecs)
target_default_compile_options_c(flecs)
if(FLECS_DEVELOPER_WARNINGS)
target_default_compile_warnings_c(flecs)
endif()
target_include_directories(flecs PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
list(APPEND FLECS_TARGETS flecs)
endif()
# build the static library
if(FLECS_STATIC_LIBS)
add_library(flecs_static STATIC ${INC} ${SRC})
add_library(flecs::flecs_static ALIAS flecs_static)
target_default_compile_options_c(flecs_static)
if(FLECS_DEVELOPER_WARNINGS)
target_default_compile_warnings_c(flecs_static)
endif()
if(FLECS_PIC)
set_property(TARGET flecs_static PROPERTY POSITION_INDEPENDENT_CODE ON)
endif()
target_include_directories(flecs_static PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_compile_definitions(flecs_static PUBLIC flecs_STATIC)
list(APPEND FLECS_TARGETS flecs_static)
endif()
# define the install steps
include(GNUInstallDirs)
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING
PATTERN "*.h"
PATTERN "*.hpp")
install(TARGETS ${FLECS_TARGETS}
EXPORT flecs-export
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT flecs-export
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/flecs
NAMESPACE flecs::
FILE flecs-config.cmake)