Skip to content

Commit 5d5cd04

Browse files
committed
build(CMakeLists.txt): small changes + improved install targets
1 parent e1a1d41 commit 5d5cd04

1 file changed

Lines changed: 50 additions & 27 deletions

File tree

CMakeLists.txt

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
cmake_minimum_required(VERSION 3.30.0..4.3.0)
22
project(Nostalgia
3-
VERSION 0.1.1
3+
VERSION 0.1.3
44
LANGUAGES CXX C)
55

66
option(BUILD_SHARED_LIBS "Build the shared version of Nostalgia" OFF)
7+
option(NOSTALGIA_INSTALL "Generate install targets" ON)
78
option(NOSTALGIA_INCLUDE_GLM_HEADERS "When installing Nostalgia's headers, include Nostalgia/thirdparty/glm" ON)
89
option(NOSTALGIA_INCLUDE_JOLT_HEADERS "When installing Nostalgia's headers, include Nostalgia/thirdparty/Jolt" ON)
10+
option(NOSTALGIA_ADD_SUFFIX_TO_DEBUG_BUILD "When building the debug version of Nostalgia, name the library 'NostalgiaDebug'" ON)
911

10-
set(NOSTALGIA_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/Nostalgia")
11-
set(NOSTALGIA_PCH_SRC ${NOSTALGIA_ROOT}/Nostalgia.hpp)
12-
13-
# taken from brotli
1412
if(NOT CMAKE_BUILD_TYPE)
15-
message(STATUS "Setting build type to Release as none was specified")
1613
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
17-
else()
18-
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
14+
endif()
15+
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
16+
17+
if(${NOSTALGIA_ADD_SUFFIX_TO_DEBUG_BUILD} AND "${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
18+
set(NOSTALGIA_LIB_VERSION_SUFFIX Debug)
1919
endif()
2020

21+
set(NOSTALGIA_LIBRARY_NAME Nostalgia${NOSTALGIA_LIB_VERSION_SUFFIX})
22+
set(NOSTALGIA_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Nostalgia)
23+
set(NOSTALGIA_PCH_SRC ${NOSTALGIA_ROOT}/Nostalgia.hpp)
24+
2125
if(MSVC)
2226
set(NOSTALGIA_JPH_DEFINITIONS JPH_PROFILE_ENABLED JPH_USE_DX12)
2327
else()
@@ -32,12 +36,22 @@ add_custom_target(EmbedAssets
3236
include(Sources.cmake)
3337
include(Thirdparty.cmake)
3438

35-
add_library(Nostalgia ${LIBRARY_VERSION} ${NOSTALGIA_SRC_FILES} ${NOSTALGIA_OBJ_FILES})
36-
add_dependencies(Nostalgia EmbedAssets)
37-
target_compile_definitions(Nostalgia PUBLIC
39+
add_library(${NOSTALGIA_LIBRARY_NAME} ${LIBRARY_VERSION} ${NOSTALGIA_SRC_FILES} ${NOSTALGIA_OBJ_FILES})
40+
add_dependencies(${NOSTALGIA_LIBRARY_NAME}
41+
EmbedAssets
42+
freetype-object
43+
zlib-object
44+
bz2-object
45+
brotlicommon-object
46+
brotlidec-object
47+
brotlienc-object
48+
png-object
49+
glfw-object
50+
Jolt-object)
51+
target_compile_definitions(${NOSTALGIA_LIBRARY_NAME} PUBLIC
3852
${NOSTALGIA_VERSION_DEFINITION}
3953
${NOSTALGIA_JPH_DEFINITIONS})
40-
target_link_libraries(Nostalgia PRIVATE
54+
target_link_libraries(${NOSTALGIA_LIBRARY_NAME} PRIVATE
4155
freetype-object
4256
zlib-object
4357
bz2-object
@@ -48,10 +62,10 @@ target_link_libraries(Nostalgia PRIVATE
4862
glfw-object
4963
Jolt-object)
5064

51-
target_precompile_headers(Nostalgia PUBLIC
65+
target_precompile_headers(${NOSTALGIA_LIBRARY_NAME} PUBLIC
5266
"$<$<COMPILE_LANGUAGE:CXX>:${NOSTALGIA_PCH_SRC}>"
5367
"$<$<COMPILE_LANGUAGE:C>:<stddef.h$<ANGLE-R>>")
54-
target_include_directories(Nostalgia
68+
target_include_directories(${NOSTALGIA_LIBRARY_NAME}
5569
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
5670
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
5771
PUBLIC ${NOSTALGIA_ROOT}
@@ -67,28 +81,36 @@ if(NOSTALGIA_INCLUDE_JOLT_HEADERS)
6781
set(NOSTALGIA_HEADERS ${NOSTALGIA_HEADERS} ${NOSTALGIA_JOLT_HEADERS})
6882
endif()
6983

70-
if(UNIX)
71-
install(TARGETS Nostalgia DESTINATION lib)
72-
84+
if(NOSTALGIA_INSTALL)
7385
# Stolen from JoltPhysics/Build/CMakeLists.txt:338-345
7486
foreach(HEADER_FILE ${NOSTALGIA_HEADERS})
7587
string(REPLACE ${NOSTALGIA_ROOT} "Nostalgia" RELATIVE_HEADER_FILE ${HEADER_FILE})
7688
get_filename_component(DESTINATION_PATH ${RELATIVE_HEADER_FILE} DIRECTORY)
7789
cmake_path(SET DST_FILE NORMALIZE "${CMAKE_INSTALL_INCLUDEDIR}/${DESTINATION_PATH}")
7890
install(FILES ${HEADER_FILE} DESTINATION ${DST_FILE})
7991
endforeach()
92+
# Install the engine last; this lets users install headers without building the library
93+
# it also lets the more important build message show up at the bottom.
94+
if(WIN32)
95+
install(TARGETS ${NOSTALGIA_LIBRARY_NAME})
96+
set(_install_dir ${CMAKE_INSTALL_PREFIX})
97+
else()
98+
install(TARGETS ${NOSTALGIA_LIBRARY_NAME} DESTINATION lib)
99+
set(_install_dir ${CMAKE_INSTALL_PREFIX}/lib)
100+
endif()
101+
message(STATUS "Library Install Dir: ${_install_dir}")
102+
message(STATUS "Headers Install Dir: ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}")
80103
endif()
81104

82-
83105
################
84106
#### EDITOR ####
85107
################
86108
set(EDITOR_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/Editor)
87109

88110
if(BUILD_SHARED_LIBS)
89-
set(EDITOR_ENGINE_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}Nostalgia${CMAKE_SHARED_LIBRARY_SUFFIX})
111+
set(EDITOR_ENGINE_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_SHARED_LIBRARY_PREFIX}${NOSTALGIA_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX})
90112
else()
91-
set(EDITOR_ENGINE_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}Nostalgia${CMAKE_STATIC_LIBRARY_SUFFIX})
113+
set(EDITOR_ENGINE_LIBRARY ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}${NOSTALGIA_LIBRARY_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX})
92114
endif()
93115

94116
if(WIN32 OR MINGW)
@@ -98,36 +120,37 @@ else()
98120
endif()
99121

100122
add_executable(NostalgiaGoggles ${EDITOR_SRC_FILES})
123+
add_dependencies(NostalgiaGoggles ${NOSTALGIA_LIBRARY_NAME})
101124
target_include_directories(NostalgiaGoggles
102125
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${EDITOR_ROOT}/thirdparty/freetype
103126
PUBLIC ${EDITOR_ROOT} ${EDITOR_ROOT}/thirdparty ${NOSTALGIA_ROOT}/thirdparty/JoltPhysics)
104127
target_link_directories(NostalgiaGoggles PUBLIC ${CMAKE_CURRENT_BINARY_DIR} ${EDITOR_LIBRARIES_DIR})
105128
target_link_libraries(NostalgiaGoggles PUBLIC ${EDITOR_ENGINE_LIBRARY} getargs)
106129

107130
if(MSVC)
108-
target_compile_features(Nostalgia PUBLIC cxx_std_23)
131+
target_compile_features(${NOSTALGIA_LIBRARY_NAME} PUBLIC cxx_std_23)
109132
target_compile_features(NostalgiaGoggles PUBLIC cxx_std_23)
110-
set_property(TARGET Nostalgia PROPERTY
133+
set_property(TARGET ${NOSTALGIA_LIBRARY_NAME} PROPERTY
111134
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
112135
set_property(TARGET NostalgiaGoggles PROPERTY
113136
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
114137
set_property(TARGET Jolt PROPERTY
115138
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
116139
else()
117-
target_compile_features(Nostalgia PUBLIC cxx_std_26)
140+
target_compile_features(${NOSTALGIA_LIBRARY_NAME} PUBLIC cxx_std_26)
118141
target_compile_features(NostalgiaGoggles PUBLIC cxx_std_26)
119142
endif()
120143

121144
if(MINGW)
122145
# std:: print, println, ...
123-
target_link_libraries(Nostalgia PUBLIC stdc++exp)
146+
target_link_libraries(${NOSTALGIA_LIBRARY_NAME} PUBLIC stdc++exp)
124147
target_link_libraries(NostalgiaGoggles PUBLIC stdc++exp)
125148
endif()
126149

127-
if(${CMAKE_BUILD_TYPE} STREQUAL Debug)
150+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
128151
if(NOT MSVC AND ${CMAKE_CXX_COMPILER_ID} EQUAL Clang)
129-
target_compile_options(Nostalgia PUBLIC -Wall -O0 -g -fsanitize=address)
130-
target_link_options(Nostalgia PUBLIC -Wall -O0 -g -fsanitize=address)
152+
target_compile_options(${NOSTALGIA_LIBRARY_NAME} PUBLIC -Wall -O0 -g -fsanitize=address)
153+
target_link_options(${NOSTALGIA_LIBRARY_NAME} PUBLIC -Wall -O0 -g -fsanitize=address)
131154
target_compile_options(NostalgiaGoggles PUBLIC -Wall -O0 -g -fsanitize=address)
132155
target_link_options(NostalgiaGoggles PUBLIC -Wall -O0 -g -fsanitize=address)
133156
endif()

0 commit comments

Comments
 (0)