diff --git a/.clang-format b/.clang-format index cde41090d..7410ab0dd 100644 --- a/.clang-format +++ b/.clang-format @@ -120,3 +120,6 @@ Standard: Latest TabWidth: 4 UseTab: Never ... +--- +Language: Json +BasedOnStyle: llvm diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a1cd9a9b0..e504a63bd 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,17 +16,13 @@ jobs: submodules: recursive - uses: microsoft/setup-msbuild@v1.0.2 - name: Configure - shell: bash - run: | - mkdir build - cd build - cmake .. -G "Visual Studio 17 2022" -DCMAKE_INSTALL_PREFIX=$HOME/slang/ -DSLANG_INCLUDE_PYLIB=ON + run: cmake --preset win64-release -DSLANG_INCLUDE_PYLIB=ON - name: Build - run: msbuild build/INSTALL.vcxproj -m -p:configuration=release -p:platform=x64 + run: cmake --build build --target install -j8 - name: Run tests run: | cd build - ctest -C Release --output-on-failure + ctest --output-on-failure build_macos: runs-on: macos-latest diff --git a/.gitignore b/.gitignore index bd075e5a6..3ff328851 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,13 @@ .vs/ .vscode/ .venv/ +.idea/ build/ +install/ compile_commands.json CMakeSettings.json *egg-info/ +cmake-build-*/ +prefix/ +CMakeLists.txt.user +CMakeUserPresets.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 83c002972..744d82eb1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -27,6 +27,7 @@ repos: - id: check-case-conflict - id: check-merge-conflict - id: check-yaml + args: [--allow-multiple-documents] - id: debug-statements - id: end-of-file-fixer - id: fix-byte-order-marker diff --git a/CMakeLists.txt b/CMakeLists.txt index 40096e1d1..e5ecfca55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ # slang - cmake entry point -cmake_minimum_required(VERSION 3.15) +cmake_minimum_required(VERSION 3.15...3.24) # Determine if slang is built as a subproject (using add_subdirectory) or if it # is the master project. @@ -18,10 +18,8 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) "'CMakeCache.txt' and 'CMakeFiles/' before building again.") endif() -# Set path for additional cmake modules. -set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) - # Determine our project version by looking at git tags. +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH}) include(gitversion) get_git_version(SLANG_VERSION_MAJOR SLANG_VERSION_MINOR SLANG_VERSION_PATCH SLANG_VERSION_HASH SLANG_VERSION_STRING) @@ -117,11 +115,22 @@ foreach( endif() endforeach() -# The Unicode defines need to be set for all modern Windows projects (newer than -# Windows 98). +# Defaults for a bunch of Windows-specific junk. These are required by all +# targets to build and run correctly and don't affect ABI so shouldn't need +# target_ specific commands. if(CMAKE_SYSTEM_NAME MATCHES "Windows") - add_definitions(/DUNICODE) - add_definitions(/D_UNICODE) + add_compile_definitions(NOMINMAX) + add_compile_definitions(UNICODE) + add_compile_definitions(_UNICODE) + add_compile_definitions(WIN32_LEAN_AND_MEAN) + add_compile_definitions(_SCL_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_SECURE_NO_WARNINGS) + add_compile_definitions(_CRT_SECURE_NO_DEPRECATE) + add_compile_definitions(_CRT_NONSTDC_NO_WARNINGS) +endif() + +if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") + add_compile_options(/utf-8) endif() # Always require C++17 or later, no extensions. @@ -130,60 +139,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") - # Disable MSVC language extensions, which for some reason are not covered by - # the CMAKE_CXX_EXTENSIONS option. - add_compile_options(/permissive-) - add_compile_options(/Zc:__cplusplus) - add_compile_options(/Zc:externConstexpr) - add_compile_options(/Zc:inline) - add_compile_options(/Zc:preprocessor) - add_compile_options(/Zc:throwingNew) - add_compile_options(/utf-8) - - # Ignore warnings in external headers - add_compile_options(/external:anglebrackets /external:W0) - if(CMAKE_BUILD_TYPE MATCHES "Debug") - # Use fast linking - string(REGEX - REPLACE "/debug" "/DEBUG:FASTLINK" CMAKE_EXE_LINKER_FLAGS_DEBUG - "${CMAKE_EXE_LINKER_FLAGS_DEBUG}") - string(REGEX - REPLACE "/debug" "/DEBUG:FASTLINK" CMAKE_SHARED_LINKER_FLAGS_DEBUG - "${CMAKE_SHARED_LINKER_FLAGS_DEBUG}") add_compile_options(/DDEBUG) - - # Ignore annoying "missing pdb" warnings - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4099") - else() - add_compile_options(/GS-) # Disable buffer overrun checks - add_compile_options(/GL) # Whole program optimization - add_compile_options(/Zi) # Generate debug info even in release - - set(REL_LINK_FLAGS "/LTCG /DEBUG:FULL /OPT:REF /OPT:ICF /INCREMENTAL:NO") - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${REL_LINK_FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS - "${CMAKE_SHARED_LINKER_FLAGS} ${REL_LINK_FLAGS}") - set(CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /LTCG") endif() - - # Ignore annoying DELAYLOAD warnings - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ignore:4199") - - set(SLANG_WARN_FLAGS "/W4" "/WX") + set(SLANG_WARN_FLAGS "") else() # Always include debug info add_compile_options(-g) - # Color in diagnostics please - if(CMAKE_GENERATOR MATCHES "Ninja") - if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - add_compile_options(-Xclang -fcolor-diagnostics) - else() - add_compile_options(-fdiagnostics-color) - endif() - endif() - if(CMAKE_BUILD_TYPE MATCHES "Debug") add_compile_options(-DDEBUG) endif() diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 000000000..c03c5108e --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,92 @@ +{ + "version": 3, + "configurePresets": [ + { + "name": "dev-mode", + "hidden": true, + "warnings": { + "dev": true, + "deprecated": true, + "uninitialized": true, + "unusedCli": true, + "systemVars": false + }, + "errors": { + "dev": true, + "deprecated": true + } + }, + { + "name": "windows-base", + "hidden": true, + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/${presetName}", + "installDir": "${sourceDir}/install/${presetName}", + "cacheVariables": { + "CMAKE_CXX_COMPILER": "cl.exe", + "CMAKE_CXX_FLAGS": "/nologo /DWIN32 /D_WINDOWS /MP /W4 /WX /utf-8 /external:anglebrackets /external:W0 /permissive- /volatile:iso /Zc:inline /Zc:preprocessor /EHsc /Zc:__cplusplus /Zc:externConstexpr /Zc:throwingNew" + }, + "condition": { + "type": "equals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + } + }, + { + "name": "windows-debug", + "hidden": true, + "inherits": "windows-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Debug", + "CMAKE_CXX_FLAGS_DEBUG": "/MDd /Zi /Ob0 /Od /RTC1", + "CMAKE_EXE_LINKER_FLAGS_DEBUG": "/nologo /DEBUG:FASTLINK", + "CMAKE_SHARED_LINKER_FLAGS_DEBUG": "/nologo /DEBUG:FASTLINK" + } + }, + { + "name": "windows-release", + "hidden": true, + "inherits": "windows-base", + "cacheVariables": { + "CMAKE_BUILD_TYPE": "Release", + "CMAKE_CXX_FLAGS_RELEASE": "/MD /O2 /Ob3 /GS- /DNDEBUG" + } + }, + { + "name": "win64-debug", + "displayName": "Win64 Debug", + "inherits": "windows-debug", + "architecture": { + "value": "x64", + "strategy": "external" + } + }, + { + "name": "win64-release", + "displayName": "Win64 Release", + "inherits": "windows-release", + "architecture": { + "value": "x64", + "strategy": "external" + } + }, + { + "name": "win32-debug", + "displayName": "Win32 Debug", + "inherits": "windows-debug", + "architecture": { + "value": "x86", + "strategy": "external" + } + }, + { + "name": "win32-release", + "displayName": "Win32 Release", + "inherits": "windows-release", + "architecture": { + "value": "x86", + "strategy": "external" + } + } + ] +} diff --git a/source/util/OS.cpp b/source/util/OS.cpp index 2d64e2726..fbfc061e6 100644 --- a/source/util/OS.cpp +++ b/source/util/OS.cpp @@ -7,9 +7,6 @@ #include "slang/util/OS.h" #if defined(_MSC_VER) -# pragma warning(disable : 4996) // _CRT_SECURE_NO_WARNINGS -# define NOMINMAX -# define WIN32_LEAN_AND_MEAN # include # include # include diff --git a/source/util/String.cpp b/source/util/String.cpp index c672d5aa7..9cf002482 100644 --- a/source/util/String.cpp +++ b/source/util/String.cpp @@ -12,8 +12,6 @@ #include "slang/util/SmallVector.h" #if defined(_MSC_VER) -# define NOMINMAX -# define WIN32_LEAN_AND_MEAN # include #endif diff --git a/tests/unittests/UtilTests.cpp b/tests/unittests/UtilTests.cpp index a0c74e55a..ee1ba99d3 100644 --- a/tests/unittests/UtilTests.cpp +++ b/tests/unittests/UtilTests.cpp @@ -70,7 +70,7 @@ TEST_CASE("Test CommandLine -- basic") { CHECK(*d == -1234); CHECK(*ext == 9876); CHECK(*ext2 == 9999.1234e12); - CHECK(used1 == 4321); + CHECK(used1 == 4321u); CHECK(used2 == -4321); CHECK(someCounter == 2); diff --git a/tests/unittests/main.cpp b/tests/unittests/main.cpp index 0424d910e..143c17a93 100644 --- a/tests/unittests/main.cpp +++ b/tests/unittests/main.cpp @@ -6,8 +6,6 @@ #include "slang/util/BumpAllocator.h" #if defined(_MSC_VER) -# define NOMINMAX -# define WIN32_LEAN_AND_MEAN # include #endif