Skip to content

Commit

Permalink
cmake: switch windows config to be based on presets, simplify CMakeLists
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Sep 10, 2022
1 parent 0f9afc9 commit e95b430
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 70 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,6 @@ Standard: Latest
TabWidth: 4
UseTab: Never
...
---
Language: Json
BasedOnStyle: llvm
10 changes: 3 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@ jobs:
submodules: recursive
- uses: microsoft/[email protected]
- 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
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 18 additions & 55 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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()
Expand Down
92 changes: 92 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
]
}
3 changes: 0 additions & 3 deletions source/util/OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Windows.h>
# include <fcntl.h>
# include <io.h>
Expand Down
2 changes: 0 additions & 2 deletions source/util/String.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
#include "slang/util/SmallVector.h"

#if defined(_MSC_VER)
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#endif

Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/UtilTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 0 additions & 2 deletions tests/unittests/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#include "slang/util/BumpAllocator.h"

#if defined(_MSC_VER)
# define NOMINMAX
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
#endif

Expand Down

0 comments on commit e95b430

Please sign in to comment.