diff --git a/CMakeLists.txt b/CMakeLists.txt index b563ab3a..24b6e976 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -99,6 +99,9 @@ else() set_cxx_flag("-g3" DEBUG) set_cxx_flag("-g3" RELWITHDEBINFO) + set_cxx_flag("-pthread") + set_linker_flag("-pthread") + if (USE_EXTRA_OPTIMIZATION) # CMake already sets the -O3 flag on Release build and -O[1-3s] already sets the -fomit-frame-pointer flag. set_cxx_flag("-Og" DEBUG) @@ -122,8 +125,6 @@ else() endif() if (BUILD_SHARED_LIBCRN OR BUILD_STATIC_LIBCRN OR BUILD_CRUNCH OR BUILD_EXAMPLES) - set_cxx_flag("-pthread") - set_linker_flag("-pthread") add_subdirectory(crnlib crnlib) endif() diff --git a/example2/example2.cpp b/example2/example2.cpp index 0cc40a32..7d2c462e 100644 --- a/example2/example2.cpp +++ b/example2/example2.cpp @@ -99,22 +99,6 @@ int main(int argc, char* argv[]) { return error("Invalid option: %s\n", argv[i]); } - // Split the source filename into its various components. -#if defined(_WIN32) - char drive_buf[_MAX_DRIVE], dir_buf[_MAX_DIR], fname_buf[_MAX_FNAME], ext_buf[_MAX_EXT]; - if (_splitpath_s(pSrc_filename, drive_buf, _MAX_DRIVE, dir_buf, _MAX_DIR, fname_buf, _MAX_FNAME, ext_buf, _MAX_EXT)) - return error("Invalid source filename!\n"); -#else - char in_filename[FILENAME_MAX]; - strncpy(in_filename, pSrc_filename, FILENAME_MAX); - const char drive_buf[] = ""; - char *dir_buf = dirname(in_filename); - char *fname_buf = basename(in_filename); - char *dot = strrchr(fname_buf, '.'); - if (dot && dot != fname_buf) - *dot = '\0'; -#endif - // Load the source file into memory. printf("Loading source file: %s\n", pSrc_filename); crn_uint32 src_file_size; @@ -152,9 +136,22 @@ int main(int argc, char* argv[]) { // Now create the DDS file. char dst_filename[FILENAME_MAX]; - crnlib_snprintf(dst_filename, sizeof(dst_filename), "%s%s%s.dds", drive_buf, dir_buf, fname_buf); - if (out_filename[0]) + if (out_filename[0]) { strcpy(dst_filename, out_filename); + } else { + unsigned int stripped_length = UINT32_MAX; + const char* ext_begin = strrchr(pSrc_filename, '.'); + if (ext_begin) { +#ifdef _WIN32 + const char* sep = strpbrk(ext_begin, "/\\"); +#else + const char* sep = strpbrk(ext_begin, "/"); +#endif + if (!sep) + stripped_length = ext_begin - pSrc_filename; + } + crnlib_snprintf(dst_filename, sizeof(dst_filename), "%-*s.dds", stripped_length, pSrc_filename); + } printf("Writing DDS file: %s\n", dst_filename);