@@ -6,25 +6,35 @@ include(../cmake/common.cmake)
66
77project (Nabla-3rdparty LANGUAGES CXX C)
88enable_language (C CXX ASM ASM_NASM)
9+ set (BUILD_SHARED_LIBS OFF )
10+ set (SKIP_INSTALL_ALL ON )
11+ set (BUILD_TESTING OFF )
912
1013option (NBL_FORCE_RELEASE_3RDPARTY "Force map 3rdaprty's configuration regardless Nabla configuration to Release" OFF )
1114option (NBL_FORCE_RELWITHDEBINFO_3RDPARTY "Force map 3rdaprty's configuration regardless Nabla configuration to RelWithDebInfo" OFF )
1215
16+ # zlib
17+ set (ZLIB_BUILD_SHARED OFF )
18+ set (ZLIB_BUILD_STATIC ON )
19+ set (ZLIB_INSTALL OFF )
20+ set (ZLIB_BUILD_TESTING OFF )
21+ set (ZLIB_BUILD_MINIZIP OFF )
22+ add_subdirectory (zlib zlib EXCLUDE_FROM_ALL )
23+ get_target_property (ZLIB_BINARY_DIR zlibstatic "BINARY_DIR" )
24+ set_target_properties (zlibstatic PROPERTIES
25+ ARCHIVE_OUTPUT_DIRECTORY $<1:${ZLIB_BINARY_DIR} >
26+ DEBUG_POSTFIX "d"
27+ RELWITHDEBINFO_POSTFIX "rwdi"
28+ OUTPUT_NAME zlibstatic
29+ )
30+ add_library (ZLIB::ZLIB ALIAS zlibstatic) # trick projects which want to use it via alias
31+
1332# nlohmann_json
1433set (JSON_BuildTests OFF )
1534add_subdirectory (nlohmann_json nlohmann_json EXCLUDE_FROM_ALL )
1635
1736# simdjson
18- set (_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} )
19- set (_OLD_BUILD_STATIC_LIBS ${BUILD_STATIC_LIBS} )
20- set (_OLD_BUILD_TESTING ${BUILD_TESTING} )
21- set (BUILD_SHARED_LIBS OFF )
22- set (BUILD_STATIC_LIBS OFF )
23- set (BUILD_TESTING OFF )
2437add_subdirectory (simdjson simdjson EXCLUDE_FROM_ALL )
25- set (BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS} )
26- set (BUILD_STATIC_LIBS ${_OLD_BUILD_STATIC_LIBS} )
27- set (BUILD_TESTING ${_OLD_BUILD_TESTING} )
2838
2939# freetype2
3040set (FT_WITH_HARFBUZZ OFF )
@@ -87,64 +97,6 @@ endif()
8797# boost
8898add_subdirectory (boost boost EXCLUDE_FROM_ALL )
8999
90- # zlib (target is zlibstatic)
91- set (_OLD_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} )
92- set (_OLD_SKIP_INSTALL_ALL ${SKIP_INSTALL_ALL} )
93- set (BUILD_SHARED_LIBS OFF )
94- set (SKIP_INSTALL_ALL ON )
95-
96- file (LOCK "${CMAKE_CURRENT_SOURCE_DIR} /zlib" DIRECTORY GUARD PROCESS RESULT_VARIABLE NBL_LOCK TIMEOUT 60)
97- add_subdirectory (zlib zlib EXCLUDE_FROM_ALL )
98- if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /zlib/zconf.h.included" )
99- execute_process (COMMAND "${CMAKE_COMMAND} " -E rename zconf.h.included zconf.h
100- WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR} /zlib"
101- ) # clean zlib git working-tree
102- endif ()
103- file (LOCK "${CMAKE_CURRENT_SOURCE_DIR} /zlib" DIRECTORY RELEASE RESULT_VARIABLE NBL_LOCK)
104- set (SKIP_INSTALL_ALL ${_OLD_SKIP_INSTALL_ALL} )
105- set (BUILD_SHARED_LIBS ${_OLD_BUILD_SHARED_LIBS} )
106-
107- get_target_property (ZLIB_SOURCE_DIR zlibstatic "SOURCE_DIR" )
108- get_target_property (ZLIB_BINARY_DIR zlibstatic "BINARY_DIR" )
109- get_filename_component (_ORIGINAL_SOURCE_ "${ZLIB_SOURCE_DIR} " ABSOLUTE )
110- get_filename_component (_COPY_BIN_SOURCE_ "${ZLIB_BINARY_DIR} /copy_source" ABSOLUTE )
111-
112- add_custom_target (zlib_copy
113- COMMAND ${CMAKE_COMMAND} -E rm -Rf "${_COPY_BIN_SOURCE_} "
114- COMMAND ${CMAKE_COMMAND} -E copy_directory "${_ORIGINAL_SOURCE_} " "${_COPY_BIN_SOURCE_} "
115- COMMAND ${CMAKE_COMMAND} -E rm -f ${_COPY_BIN_SOURCE_} /zconf.h # no duplicates in include search paths!
116- COMMENT "Copying zlib..."
117- )
118-
119- unset (_ORIGINAL_SOURCE_)
120- unset (_COPY_BIN_SOURCE_)
121-
122- #https://stackoverflow.com/questions/47175912/using-cmake-how-to-stop-the-debug-and-release-subdirectories
123- set_target_properties (zlibstatic PROPERTIES ARCHIVE_OUTPUT_DIRECTORY $<1:${ZLIB_BINARY_DIR} >)
124- set_target_properties (zlibstatic PROPERTIES DEBUG_POSTFIX "d" )
125- if (MSVC )
126- set (ZLIB_BINARY_DIR_DEBUG "${ZLIB_BINARY_DIR} " )
127- set (ZLIB_BINARY_DIR_RELEASE "${ZLIB_BINARY_DIR} " )
128- set (ZLIB_BINARY_DIR_RELWITHDEBINFO "${ZLIB_BINARY_DIR} " )
129- get_target_property (ZLIB_NAME zlibstatic "NAME" )
130- else ()
131- set (ZLIB_BINARY_DIR_DEBUG ${ZLIB_BINARY_DIR} )
132- set (ZLIB_BINARY_DIR_RELEASE ${ZLIB_BINARY_DIR} )
133- set (ZLIB_BINARY_DIR_RELWITHDEBINFO ${ZLIB_BINARY_DIR} )
134- get_target_property (ZLIB_NAME zlibstatic "OUTPUT_NAME" )
135- endif ()
136-
137- get_target_property (ZLIB_DEBUG_POSTFIX zlibstatic "DEBUG_POSTFIX" )
138- set (ZLIB_INCLUDE_DIR "${THIRD_PARTY_SOURCE_DIR} /zlib;${THIRD_PARTY_BINARY_DIR} /zlib" CACHE INTERNAL "" FORCE)
139- set (ZLIB_LIBRARY_DEBUG "${ZLIB_BINARY_DIR_DEBUG} /${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_NAME}${ZLIB_DEBUG_POSTFIX}${CMAKE_STATIC_LIBRARY_SUFFIX} " CACHE INTERNAL "" FORCE)
140- set (ZLIB_LIBRARY_RELEASE "${ZLIB_BINARY_DIR_RELEASE} /${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} " CACHE INTERNAL "" FORCE)
141- set (ZLIB_LIBRARY_RELWITHDEBINFO "${ZLIB_BINARY_DIR_RELWITHDEBINFO} /${CMAKE_STATIC_LIBRARY_PREFIX}${ZLIB_NAME}${CMAKE_STATIC_LIBRARY_SUFFIX} " CACHE INTERNAL "" FORCE)
142- set (ZLIB_LIBRARY # for PNGLIB purposes
143- $<$<CONFIG:Debug>:${ZLIB_LIBRARY_DEBUG} >
144- $<$<CONFIG:Release>:${ZLIB_LIBRARY_RELEASE} >
145- $<$<CONFIG:RelWithDebInfo>:${ZLIB_LIBRARY_RELWITHDEBINFO} >
146- CACHE INTERNAL "" FORCE)
147-
148100set (SPIRV_HEADERS_SKIP_INSTALL ON CACHE INTERNAL "Skip SPIRV-Headers install" )
149101set (SPIRV_HEADERS_SKIP_EXAMPLES ON CACHE INTERNAL "Skip SPIRV-Headers examples" )
150102add_subdirectory ("${DXC_SPIRV_HEADERS_DIR} " SPIRV-Headers EXCLUDE_FROM_ALL )
@@ -167,29 +119,67 @@ set(SHADERC_SKIP_INSTALL ON CACHE INTERNAL "Install shaderc?")
167119add_subdirectory (shaderc shaderc EXCLUDE_FROM_ALL )
168120
169121# libjpeg-turbo
170- option (WITH_SIMD "libjpeg-turbo" ON )
171- option (WITH_MEM_SRCDST "libjpeg-turbo" ON )
172- option (WITH_TURBOJPEG "libjpeg-turbo" ON )
173- option (ENABLE_STATIC "libjpeg-turbo" ON )
174- option (ENABLE_SHARED "libjpeg-turbo" OFF )
175- option (WITH_CRT_DLL "libjpeg-turbo" OFF )
176- option (WITH_FUZZ "libjpeg-turbo" OFF )
177- option (WITH_JAVA "libjpeg-turbo" OFF )
178- set (CMAKE_INSTALL_DOCDIR "${CMAKE_CURRENT_BINARY_DIR} /libjpeg-turbo/install/docdir" )
179- set (CMAKE_INSTALL_MANDIR "${CMAKE_CURRENT_BINARY_DIR} /libjpeg-turbo/install/mandir" )
180- add_subdirectory (libjpeg-turbo libjpeg-turbo EXCLUDE_FROM_ALL )
181- NBL_TARGET_FORCE_ASSEMBLER_EXECUTABLE(simd ASM_NASM libjpeg-turbo/simd/)
182-
183- unset (CMAKE_INSTALL_DOCDIR)
184- unset (CMAKE_INSTALL_MANDIR)
122+ set (NBL_JPEG_CMAKE_OPTIONS
123+ -DCMAKE_MSVC_RUNTIME_LIBRARY:STATIC =MultiThreaded$<$<CONFIG:Debug>:Debug>$<$<BOOL :${NBL_COMPILER_DYNAMIC_RUNTIME} >:DLL>
124+ -DCMAKE_POLICY_DEFAULT_CMP0057=NEW
125+ -DCMAKE_POLICY_DEFAULT_CMP0091=NEW
126+ -DENABLE_SHARED=OFF
127+ -DENABLE_STATIC=ON
128+ -DWITH_CRT_DLL=ON
129+ -DWITH_SIMD=ON
130+ -DWITH_MEM_SRCDST=ON
131+ -DWITH_TURBOJPEG=ON
132+ -DWITH_FUZZ=OFF
133+ -DWITH_JAVA=OFF
134+ )
135+
136+ if (NOT NBL_IS_MULTI_CONFIG)
137+ list (APPEND NBL_JPEG_CMAKE_OPTIONS "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} " )
138+ endif ()
139+
140+ if (NOT CMAKE_GENERATOR MATCHES "Ninja*" )
141+ list (APPEND NBL_JPEG_CMAKE_OPTIONS -Ax64)
142+ endif ()
143+
144+ if (CMAKE_GENERATOR_TOOLSET)
145+ list (APPEND NBL_JPEG_CMAKE_OPTIONS -T "${CMAKE_GENERATOR_TOOLSET} " )
146+ endif ()
147+
148+ if (CMAKE_TOOLCHAIN_FILE)
149+ list (APPEND NBL_JPEG_CMAKE_OPTIONS "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE} " )
150+ endif ()
151+
152+ # TODO: might find an alternative library which supports add_subdirectory, untill then we need to switch to a workaround just like
153+ # we do for DXC due to: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/0b742742c873025e2a127918d4969238ace7ae5b/CMakeLists.txt#L69
154+ execute_process (COMMAND "${CMAKE_COMMAND} " -S "${CMAKE_CURRENT_SOURCE_DIR} /libjpeg-turbo" -B "${CMAKE_CURRENT_BINARY_DIR} /libjpeg-turbo" -G "${CMAKE_GENERATOR} " ${NBL_JPEG_CMAKE_OPTIONS}
155+ RESULT_VARIABLE JPEG_CMAKE_RESULT
156+ OUTPUT_VARIABLE JPEG_CMAKE_STREAM_PIPE
157+ )
158+
159+ if (NOT "${JPEG_CMAKE_RESULT} " STREQUAL "0" )
160+ message (FATAL_ERROR "${JPEG_CMAKE_STREAM_PIPE} " )
161+ endif ()
162+
163+ set (JPEG_LIB_OUTPUT "${THIRD_PARTY_BINARY_DIR} /libjpeg-turbo/$<CONFIG>/jpeg-static${CMAKE_STATIC_LIBRARY_SUFFIX} " )
164+ add_custom_command (OUTPUT ${JPEG_LIB_OUTPUT}
165+ COMMAND "${CMAKE_COMMAND} " --build "${THIRD_PARTY_BINARY_DIR} /libjpeg-turbo" -t jpeg-static --config $<CONFIG>
166+ COMMENT "Building libjpeg-turbo static library"
167+ VERBATIM USES_TERMINAL
168+ )
169+ add_library (jpeg-static INTERFACE ${JPEG_LIB_OUTPUT} )
170+ target_include_directories (jpeg-static INTERFACE
171+ "${THIRD_PARTY_SOURCE_DIR} /libjpeg-turbo/src"
172+ "${THIRD_PARTY_BINARY_DIR} /libjpeg-turbo"
173+ )
174+ target_link_libraries (jpeg-static INTERFACE "${JPEG_LIB_OUTPUT} " )
185175
186176# blake3
187177add_subdirectory (blake/c EXCLUDE_FROM_ALL )
188178
189- #manipulating libpng cmake options from within cmake script
190- set (PNG_BUILD_ZLIB ON CACHE INTERNAL "" FORCE) # get ZLIB from our /3rdparty
191- option (PNG_SHARED "Build shared lib" OFF )
192- option (PNG_TESTS "Build libpng tests" OFF )
179+ # manipulating libpng cmake options from within cmake script
180+ set (PNG_BUILD_ZLIB OFF )
181+ set (PNG_SHARED OFF )
182+ set (PNG_TESTS OFF )
193183add_subdirectory (libpng libpng EXCLUDE_FROM_ALL )
194184add_dependencies (png_static zlibstatic)
195185
@@ -441,7 +431,7 @@ if (NBL_BUILD_MITSUBA_LOADER)
441431 )
442432 set (MITSUBA_LOADER_DEPENDENTS ${MITSUBA_LOADER_DEPENDENTS} PARENT_SCOPE)
443433 set (MITSUBA_LOADER_DEPENDENT_LIBS
444- expat " ${ZLIB_LIBRARY} "
434+ expat zlibstatic
445435 )
446436 set (MITSUBA_LOADER_DEPENDENT_LIBS ${MITSUBA_LOADER_DEPENDENT_LIBS} PARENT_SCOPE)
447437endif ()
@@ -468,7 +458,6 @@ set(NBL_3RDPARTY_TARGETS
468458 zlibstatic
469459 shaderc_util
470460 shaderc
471- jpeg-static
472461 bz2_static
473462 simdjson
474463 nlohmann_json
0 commit comments