Skip to content

Commit

Permalink
add cmake presets and workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
huangqinjin committed May 5, 2024
1 parent ed7b861 commit 7815660
Show file tree
Hide file tree
Showing 3 changed files with 350 additions and 0 deletions.
166 changes: 166 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
{
"version": 5,
"cmakeMinimumRequired": {
"major": 3,
"minor": 26,
"patch": 0
},
"configurePresets": [
{
"name": "default",
"generator": "Ninja Multi-Config",
"binaryDir": "${sourceDir}/cmake-build-${presetName}",
"cacheVariables": {
"CMAKE_CXX_STANDARD": "23",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "gcc",
"inherits": "default",
"cacheVariables": {
"CMAKE_C_COMPILER": "gcc",
"CMAKE_CXX_COMPILER": "g++"
}
},
{
"name": "clang",
"inherits": "default",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang",
"CMAKE_CXX_COMPILER": "clang++"
},
"environment": {
"CXXFLAGS": "--start-no-unused-arguments -stdlib=libc++ --end-no-unused-arguments $penv{CXXFLAGS}"
}
},
{
"name": "clang-cl",
"inherits": "default",
"cacheVariables": {
"CMAKE_C_COMPILER": "clang-cl",
"CMAKE_CXX_COMPILER": "clang-cl",
"CMAKE_MT": "llvm-mt"
}
},
{
"name": "x-clang-cl",
"inherits": "clang-cl",
"cacheVariables": {
"CMAKE_C_COMPILER_TARGET": "x86_64-pc-windows-msvc",
"CMAKE_CXX_COMPILER_TARGET": "x86_64-pc-windows-msvc",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>",
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_SYSTEM_VERSION": "10",
"CMAKE_CROSSCOMPILING_EMULATOR": "env;WINEDEBUG=-all;wine64"
},
"environment": {
"CFLAGS": "-winsysroot /opt/msvc $penv{CFLAGS}",
"CXXFLAGS": "-winsysroot /opt/msvc $penv{CXXFLAGS}",
"LDFLAGS": "-winsysroot:/opt/msvc $penv{LDFLAGS}"
},
"condition": {
"string": "${hostSystemName}",
"type": "notInList",
"list" : [
"Windows"
]
}
},
{
"name": "msvc-wine",
"inherits": "default",
"cacheVariables": {
"CMAKE_C_COMPILER": "/opt/msvc/bin/x64/cl.exe",
"CMAKE_CXX_COMPILER": "/opt/msvc/bin/x64/cl.exe",
"CMAKE_RC_COMPILER": "/opt/msvc/bin/x64/rc.exe",
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>",
"CMAKE_MSVC_DEBUG_INFORMATION_FORMAT": "$<$<CONFIG:Debug,RelWithDebInfo>:$<IF:$<STREQUAL:${hostSystemName},Darwin>,Embedded,ProgramDatabase>>",
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_SYSTEM_VERSION": "10",
"CMAKE_CROSSCOMPILING_EMULATOR": "env;WINEDEBUG=-all;wine64"
},
"condition": {
"string": "${hostSystemName}",
"type": "notInList",
"list" : [
"Windows"
]
}
},
{
"name": "x-mingw-gcc",
"inherits": "default",
"cacheVariables": {
"CMAKE_C_COMPILER": "x86_64-w64-mingw32-gcc",
"CMAKE_CXX_COMPILER": "x86_64-w64-mingw32-g++",
"CMAKE_SYSTEM_NAME": "Windows",
"CMAKE_SYSTEM_VERSION": "10",
"CMAKE_CROSSCOMPILING_EMULATOR": "env;WINEPATH=/usr/x86_64-w64-mingw32/sys-root/mingw/bin;WINEDEBUG=-all;wine64"
},
"condition": {
"string": "${hostSystemName}",
"type": "notInList",
"list" : [
"Windows"
]
}
},
{
"name": "msys",
"inherits": "default",
"environment": {
"MSYSTEM_PREFIX": "/usr",
"MSYSTEM_PATH": "C:/msys64$env{MSYSTEM_PREFIX}/bin",
"PATH": "$env{MSYSTEM_PATH}${pathListSep}$penv{PATH}"
},
"condition": {
"string": "${hostSystemName}",
"type": "inList",
"list" : [
"Windows"
]
}
},
{
"name": "mingw-w64",
"inherits": "msys",
"environment": {
"MSYSTEM_PREFIX": "/mingw64"
}
},
{
"name": "mingw-ucrt64",
"inherits": "msys",
"environment": {
"MSYSTEM_PREFIX": "/ucrt64"
}
},
{
"name": "mingw-clang64",
"inherits": "msys",
"environment": {
"MSYSTEM_PREFIX": "/clang64"
}
},
{
"name": "msbuild",
"inherits": "default",
"generator": "Visual Studio 17 2022",
"architecture": "x64",
"toolset": "host=x64",
"condition": {
"string": "${hostSystemName}",
"type": "inList",
"list" : [
"Windows"
]
}
},
{
"name": "msbuild-clang",
"inherits": "msbuild",
"toolset": "ClangCL"
}
]
}
91 changes: 91 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
msvc: \
named-module/msvc \
module-partition/msvc \
module-impl/msvc \
header-unit/msvc \
import-std/msvc \
shared-lib/msvc \

clang: \
named-module/clang \
module-partition/clang \
module-impl/clang \
header-unit/clang \
header-unit/clang-libcxx \
import-std/clang \
shared-lib/clang \

clang-cl: \
named-module/clang-cl \
module-partition/clang-cl \
module-impl/clang-cl \
header-unit/clang-cl \
shared-lib/clang-cl \

clang-win32: \
named-module/clang \
module-partition/clang \
module-impl/clang \
header-unit/clang \
shared-lib/clang-win32 \

clang-mingw: \
named-module/clang \
module-partition/clang \
module-impl/clang \
header-unit/clang-libcxx \
import-std/clang \
shared-lib/clang-mingw \

gcc: \
named-module/gcc \
module-partition/gcc \
module-impl/gcc \
header-unit/gcc \
shared-lib/gcc \

TARGETS1 = \
module-partition/msvc \
module-partition/clang \
module-partition/clang-cl \
header-unit/msvc \
header-unit/clang \
header-unit/clang-libcxx \
header-unit/clang-cl \
header-unit/gcc \
import-std/msvc \
import-std/clang \
shared-lib/msvc \
shared-lib/clang \
shared-lib/clang-win32 \
shared-lib/clang-mingw \
shared-lib/clang-cl \
shared-lib/gcc \

TARGETS2 = \
named-module/clang \
named-module/clang-cl \
module-partition/gcc \
module-impl/msvc \
module-impl/clang \
module-impl/clang-cl \
module-impl/gcc \

TARGETS3 = \
named-module/msvc \
named-module/gcc \

$(TARGETS1):
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean hello.exe && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean

$(TARGETS2):
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean default && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean hello.exe && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean

$(TARGETS3):
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean default-mapper && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean custom-mapper && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean hello.exe && $(LAUNCHER)hello.exe
@cd $(@D) && $(MAKE) -f Makefile.$(@F) -$(MAKEFLAGS) clean
93 changes: 93 additions & 0 deletions workflow.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
cmake_minimum_required(VERSION 3.25)

unset(ARGN)
unset(PRESET)
foreach(i RANGE ${CMAKE_ARGC})
if(NOT DEFINED ARGN)
if (CMAKE_ARGV${i} STREQUAL --)
set(ARGN [[]])
endif()
elseif(NOT DEFINED PRESET)
set(PRESET ${CMAKE_ARGV${i}})
else()
list(APPEND ARGN ${CMAKE_ARGV${i}})
endif()
endforeach()

string(TIMESTAMP UID ${PRESET}-%Y-%m-%d_%H_%M_%S)

file(CONFIGURE OUTPUT CMakeUserPresets.json CONTENT [[
{
"version": 6,
"buildPresets": [
{
"name": "@UID@",
"hidden": true,
"verbose": true,
"configurePreset": "@PRESET@"
},
{
"name": "Debug-@UID@",
"inherits": "@UID@",
"configuration": "Debug"
},
{
"name": "Release-@UID@",
"inherits": "@UID@",
"configuration": "Release"
}
],
"testPresets": [
{
"name": "@UID@",
"hidden": true,
"configurePreset": "@PRESET@",
"output": {
"verbosity": "verbose"
}
},
{
"name": "Debug-@UID@",
"inherits": "@UID@",
"configuration": "Debug"
},
{
"name": "Release-@UID@",
"inherits": "@UID@",
"configuration": "Release"
}
],
"workflowPresets": [
{
"name": "@UID@",
"steps": [
{
"type": "configure",
"name": "@PRESET@"
},
{
"type": "build",
"name": "Debug-@UID@"
},
{
"type": "build",
"name": "Release-@UID@"
},
{
"type": "test",
"name": "Debug-@UID@"
},
{
"type": "test",
"name": "Release-@UID@"
}
]
}
]
}
]] @ONLY)

execute_process(COMMAND
${CMAKE_COMMAND} --workflow --preset ${UID} ${ARGN}
COMMAND_ERROR_IS_FATAL ANY
)

0 comments on commit 7815660

Please sign in to comment.