From 7d4deb853d49dc2483122568c4d06d8805ba5d26 Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 10 Nov 2023 09:40:24 -0500 Subject: [PATCH 1/3] cmake: must set build type before project() also account for env var CMAKE_BUILD_TYPE --- CMakeLists.txt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fce957e7..aec6a106b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,16 @@ cmake_minimum_required(VERSION 3.18) +# Set a default configuration if none was specified +if (NOT CMAKE_BUILD_TYPE AND NOT DEFINED ENV{CMAKE_BUILD_TYPE}) + message(STATUS "No release type specified. Setting to 'Release'.") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) +endif() + +if(NOT CMAKE_CONFIGURATION_TYPES) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo") +endif() + project(instant-ngp VERSION 1.0 DESCRIPTION "Instant Neural Graphics Primitives" @@ -31,13 +41,6 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # Build type and C++ compiler setup ############################################################################### -# Set a default configuration if none was specified -if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) - message(STATUS "No release type specified. Setting to 'Release'.") - set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) - set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "RelWithDebInfo") -endif() - if (NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/glfw/CMakeLists.txt") message(FATAL_ERROR "Some instant-ngp dependencies are missing. " From ad83198f85446e759a0ff4b6eaa89992a4b335d4 Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 10 Nov 2023 09:42:06 -0500 Subject: [PATCH 2/3] cmake: use list(APPEND to avoid typos --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index aec6a106b..f832d726b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ option(NGP_BUILD_WITH_OPTIX "Build with OptiX to enable hardware ray tracing?" O option(NGP_BUILD_WITH_PYTHON_BINDINGS "Build bindings that allow instrumenting instant-ngp with Python?" ON) option(NGP_BUILD_WITH_VULKAN "Build with Vulkan to enable DLSS support?" ON) -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) ############################################################################### # Build type and C++ compiler setup From cf15f46be734e6cccdcc28406a5eaab00144574a Mon Sep 17 00:00:00 2001 From: scivision Date: Fri, 10 Nov 2023 09:46:36 -0500 Subject: [PATCH 3/3] cmake: use options/defns rather than direct vars --- CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f832d726b..1e3868344 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,10 +54,10 @@ if (APPLE) endif() if (MSVC) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /D_CRT_SECURE_NO_WARNINGS") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP24") + add_compile_definitions("$<$:_CRT_SECURE_NO_WARNINGS>") + add_compile_options("$<$:/MP24>") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + add_compile_options("$<$:-fPIC>") endif() set(CMAKE_CXX_STANDARD 14) @@ -211,8 +211,8 @@ list(APPEND NGP_INCLUDE_DIRECTORIES find_package(OpenMP) if (OPENMP_FOUND) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + add_compile_options("$<$:${OpenMP_C_FLAGS}>") + add_compile_options("$<$:${OpenMP_CXX_FLAGS}>") endif() if (NGP_BUILD_WITH_OPTIX)