@@ -45,6 +45,13 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
4545set (CMAKE_CXX_EXTENSIONS OFF )
4646set (CMAKE_POSITION_INDEPENDENT_CODE ON )
4747
48+ # Set default build type for single-config generators (Unix Makefiles, Ninja)
49+ # Note: Multi-config generators (Visual Studio, Xcode) ignore this
50+ if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
51+ set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE )
52+ set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo" )
53+ endif ()
54+
4855# Export compile commands for clang-tidy
4956set (CMAKE_EXPORT_COMPILE_COMMANDS ON )
5057
@@ -73,6 +80,9 @@ elseif(ANDROID)
7380elseif (APPLE )
7481 set (RAC_PLATFORM_MACOS TRUE )
7582 set (RAC_PLATFORM_NAME "macOS" )
83+ elseif (WIN32 )
84+ set (RAC_PLATFORM_WINDOWS TRUE )
85+ set (RAC_PLATFORM_NAME "Windows" )
7686elseif (UNIX )
7787 set (RAC_PLATFORM_LINUX TRUE )
7888 set (RAC_PLATFORM_NAME "Linux" )
@@ -134,6 +144,34 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|GNU")
134144 add_compile_options (-fvisibility=hidden )
135145 add_compile_options (-ffunction-sections -fdata-sections )
136146 endif ()
147+ elseif (MSVC )
148+ # MSVC compiler flags (shared across configs)
149+ add_compile_options (/W4 /WX- /wd4996 /wd4576 /FS ) # W4 = level 4 warnings, WX- = warnings as errors off, 4996 = deprecated function warnings, 4576 = non-standard cast syntax, FS = force synchronous PDB writes
150+ # Per-config flags: use generator expressions so multi-config generators (e.g. Visual Studio) get correct flags per config. /O2 and /RTC1 are incompatible.
151+ add_compile_options ("$<$<CONFIG :Release >:/O2 /DNDEBUG /GL /MP >" ) # O2 = optimize for speed, GL = whole program optimization, MP = multi-processor
152+ add_compile_options ("$<$<CONFIG :RelWithDebInfo >:/O2 /DNDEBUG /GL /MP >" )
153+ add_compile_options ("$<$<CONFIG :MinSizeRel >:/O1 /DNDEBUG /GL /MP >" )
154+ add_compile_options ("$<$<CONFIG :Debug >:/Od /Zi >" ) # Od = disable optimizations, Zi = debug information (no /RTC1 here; let CMake default or use /RTC1 only if desired)
155+ # Disable MSVC-specific warnings that are common in cross-platform code
156+ add_compile_definitions (_CRT_SECURE_NO_WARNINGS )
157+ add_compile_definitions (NOMINMAX ) # Prevent Windows.h from defining min/max macros
158+ # Use Unicode character set: Windows API and CRT use wide-char (UTF-16) variants
159+ add_compile_definitions (UNICODE _UNICODE )
160+ # https://learn.microsoft.com/en-us/cpp/build/reference/debug-generate-debug-info?view=msvc-170
161+ # The /DEBUG option puts the debugging information from linked object and library files
162+ # into a program database (PDB) file. It updates the PDB during subsequent builds of the program.
163+ #
164+ # An executable (an EXE or DLL file) created for debugging contains the name and path of the corresponding PDB.
165+ # The debugger reads the embedded name and uses the PDB when you debug the program.
166+ # The linker uses the base name of the program and the extension .pdb to name the program database,
167+ # and embeds the path where it was created. To override this default, set the /PDB option and specify a different file name.
168+ set (CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} /DEBUG" )
169+ set (CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG" )
170+ set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd" )
171+ set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT" )
172+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
173+ /Zi \
174+ /arch:SSE2" )
137175endif ()
138176
139177# =============================================================================
@@ -295,11 +333,16 @@ target_include_directories(rac_commons PRIVATE
295333# Symbol visibility for shared builds
296334if (RAC_BUILD_SHARED)
297335 target_compile_definitions (rac_commons PRIVATE RAC_BUILDING_SHARED=1 )
298- set_target_properties (rac_commons PROPERTIES
299- C_VISIBILITY_PRESET hidden
300- CXX_VISIBILITY_PRESET hidden
301- VISIBILITY_INLINES_HIDDEN ON
302- )
336+ if (WIN32 )
337+ # Windows DLL export/import is handled via __declspec in headers
338+ # No need for visibility presets on Windows
339+ else ()
340+ set_target_properties (rac_commons PROPERTIES
341+ C_VISIBILITY_PRESET hidden
342+ CXX_VISIBILITY_PRESET hidden
343+ VISIBILITY_INLINES_HIDDEN ON
344+ )
345+ endif ()
303346endif ()
304347
305348# Platform-specific linking
@@ -319,7 +362,48 @@ if(RAC_PLATFORM_ANDROID)
319362 target_link_libraries (rac_commons PUBLIC log )
320363endif ()
321364
322- target_compile_features (rac_commons PUBLIC cxx_std_17 )
365+ if (WIN32 )
366+ # Windows-specific libraries
367+ # ws2_32 for networking (if needed)
368+ # winmm for multimedia (if needed)
369+ # No specific libraries required by default, add as needed
370+
371+ # Set Windows-specific properties
372+ if (MSVC )
373+ # Set runtime library (use /MD for Release, /MDd for Debug)
374+ if (CMAKE_BUILD_TYPE STREQUAL "Release" )
375+ set_property (TARGET rac_commons PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDLL" )
376+ # Enable link-time code generation for Release builds
377+ set_target_properties (rac_commons PROPERTIES
378+ INTERPROCEDURAL_OPTIMIZATION ON
379+ )
380+ else ()
381+ set_property (TARGET rac_commons PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL" )
382+ endif ()
383+
384+ # Force synchronous PDB writes for parallel compilation and disable C4576 warning
385+ target_compile_options (rac_commons PRIVATE /FS /wd4576 )
386+
387+ # Set output file names for Windows
388+ if (RAC_BUILD_SHARED)
389+ set_target_properties (rac_commons PROPERTIES
390+ OUTPUT_NAME "rac_commons"
391+ PREFIX ""
392+ )
393+ else ()
394+ set_target_properties (rac_commons PROPERTIES
395+ OUTPUT_NAME "rac_commons"
396+ )
397+ endif ()
398+ endif ()
399+ endif ()
400+
401+ # Set C++ standard based on platform
402+ if (WIN32 )
403+ target_compile_features (rac_commons PUBLIC cxx_std_20 )
404+ else ()
405+ target_compile_features (rac_commons PUBLIC cxx_std_17 )
406+ endif ()
323407
324408# =============================================================================
325409# JNI BRIDGE (Android/JVM)
@@ -404,7 +488,12 @@ endif()
404488
405489if (RAC_BUILD_TESTS)
406490 enable_testing ()
407- add_subdirectory (tests )
491+ if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR} /tests/CMakeLists.txt" )
492+ message (STATUS "Building unit tests" )
493+ add_subdirectory (tests )
494+ else ()
495+ message (WARNING "RAC_BUILD_TESTS is ON but tests/CMakeLists.txt not found. Skipping tests." )
496+ endif ()
408497endif ()
409498
410499# =============================================================================
@@ -414,6 +503,7 @@ endif()
414503install (TARGETS rac_commons
415504 LIBRARY DESTINATION lib
416505 ARCHIVE DESTINATION lib
506+ RUNTIME DESTINATION bin # Windows DLLs go to bin
417507)
418508
419509install (DIRECTORY include/
@@ -432,7 +522,11 @@ message(STATUS "====================================")
432522message (STATUS "Platform: ${RAC_PLATFORM_NAME} " )
433523message (STATUS "Build type: ${CMAKE_BUILD_TYPE} " )
434524message (STATUS "Compiler: ${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} " )
525+ message (STATUS "C++ Standard: C++${CMAKE_CXX_STANDARD} " )
435526message (STATUS "Shared libs: ${RAC_BUILD_SHARED} " )
527+ if (WIN32 )
528+ message (STATUS "Architecture: ${CMAKE_SYSTEM_PROCESSOR} " )
529+ endif ()
436530message (STATUS "" )
437531message (STATUS "Components:" )
438532message (STATUS " Core: Logging, errors, events, memory" )
0 commit comments