Skip to content

Commit

Permalink
Merge pull request #16 from Masfo/cmake
Browse files Browse the repository at this point in the history
Convert to Cmake
  • Loading branch information
Masfo authored Sep 30, 2022
2 parents a3055f3 + ef0da50 commit fa2ee20
Show file tree
Hide file tree
Showing 16 changed files with 14,175 additions and 13,996 deletions.
144 changes: 72 additions & 72 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@


Language: Cpp
BasedOnStyle: LLVM
ColumnLimit: 120
IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -4
MaxEmptyLinesToKeep: 2
SpacesBeforeTrailingComments: 3

SpaceBeforeAssignmentOperators: true
SortIncludes: false
IncludeBlocks: Merge

Cpp11BracedListStyle: true

AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: false
AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: false

AlwaysBreakAfterReturnType : None

AlignAfterOpenBracket: Align
AlignOperands: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

IndentPPDirectives: AfterHash
IndentCaseLabels: false

KeepEmptyLinesAtTheStartOfBlocks: true

NamespaceIndentation: All
FixNamespaceComments: true

BreakStringLiterals: false
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'true'
NamespaceIndentation: All


BinPackArguments: false
BinPackParameters: false

ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false

BreakBeforeBraces: Allman
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true




Language: Cpp
BasedOnStyle: LLVM
ColumnLimit: 140
IndentWidth: 4
TabWidth: 4
AccessModifierOffset: -4
MaxEmptyLinesToKeep: 2
SpacesBeforeTrailingComments: 3

SpaceBeforeAssignmentOperators: true
SortIncludes: false
IncludeBlocks: Merge

Cpp11BracedListStyle: true

AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortIfStatementsOnASingleLine: false
AllowShortFunctionsOnASingleLine: false
AllowShortBlocksOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: false
AllowShortLoopsOnASingleLine: false
AllowShortBlocksOnASingleLine: false

AlwaysBreakAfterReturnType : None

AlignAfterOpenBracket: Align
AlignOperands: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true

IndentPPDirectives: AfterHash
IndentCaseLabels: false

KeepEmptyLinesAtTheStartOfBlocks: true

NamespaceIndentation: All
FixNamespaceComments: true

BreakStringLiterals: false
BreakBeforeBinaryOperators: All
BreakBeforeTernaryOperators: 'true'
NamespaceIndentation: All


BinPackArguments: false
BinPackParameters: false

ExperimentalAutoDetectBinPacking: false
AllowAllParametersOfDeclarationOnNextLine: false

BreakBeforeBraces: Allman
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
BeforeLambdaBody: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
SplitEmptyNamespace: true


12 changes: 0 additions & 12 deletions .github/workflows/main.yml

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ bin
/.github/workflows/main.yml
/.github/ISSUE_TEMPLATE/bug_report.md
/.github/ISSUE_TEMPLATE/feature_request.md
/.github/workflows/main.yml
8 changes: 8 additions & 0 deletions CMake/Buildinc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_custom_command(TARGET buildinc
POST_BUILD
COMMENT Run BuildInc and copy to tools
COMMAND buildinc.exe buildnumber.h BuildInc -q
#COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/bin/buildinc.exe E:/tools/global_commands
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
USES_TERMINAL
)
150 changes: 150 additions & 0 deletions CMake/SetupMSVC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(CMAKE_CXX_SYSROOT_FLAG_CODE "list(APPEND CMAKE_CXX_SOURCE_FILE_EXTENSIONS ixx)")


# setup_piku_executable(targetname exename)
function(setup_piku_executable_msvc target outputname)

set_property(TARGET "${target}" PROPERTY CXX_STANDARD 23)
set_property(TARGET "${target}" PROPERTY CXX_STANDARD_REQUIRED ON)
set_property(TARGET "${target}" PROPERTY CXX_EXTENSIONS OFF)

set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/bin)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)

if(outputname STREQUAL "")
set_target_properties(${target} PROPERTIES OUTPUT_NAME "${target}")
else()
set_target_properties(${target} PROPERTIES OUTPUT_NAME "${outputname}")
endif()

get_target_property(str ${target} OUTPUT_NAME)
message(STATUS "Output exe: " ${str})


set_target_properties("${target}" PROPERTIES DEBUG_POSTFIX "d")


set_property(TARGET "${target}" PROPERTY VS_STARTUP_PROJECT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

set_target_properties("${target}" PROPERTIES
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_SOURCE_DIR}/bin
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_SOURCE_DIR}/bin
)

message(STATUS "bin: " ${CMAKE_SOURCE_DIR}/bin)

if(MSVC)
target_compile_definitions("${target}" PRIVATE -DUNICODE)
target_compile_definitions("${target}" PRIVATE -D_UNICODE)
#target_compile_definitions("${target}" PRIVATE -D_CRT_SECURE_NO_WARNINGS)
target_compile_definitions("${target}" PRIVATE -DNOMINMAX)
target_compile_definitions("${target}" PRIVATE -DWIN32_LEAN_AND_MEAN)


target_compile_options("${target}" PRIVATE /nologo)
target_compile_options("${target}" PRIVATE -Zc:__cplusplus /Zc:alignedNew)
target_compile_options("${target}" PRIVATE /utf-8)
target_compile_options("${target}" PRIVATE /EHsc)
#target_compile_options("${target}" PRIVATE /Za)

target_compile_options("${target}" PRIVATE /fp:precise)
target_compile_options("${target}" PRIVATE /diagnostics:caret)


target_compile_options("${target}" PRIVATE /experimental:module)
target_compile_options("${target}" PRIVATE /Zc:preprocessor)
target_compile_options("${target}" PRIVATE /permissive-)
target_compile_options("${target}" PRIVATE /std:c++latest)

target_compile_options("${target}" PRIVATE /Wall)
# target_compile_options("${target}" PRIVATE /WX) # Warnings as errors


# Debug
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")

target_compile_options("${target}" PRIVATE /JMC) # Just my debugging
target_compile_definitions("${target}" PRIVATE -DDEBUG)

target_compile_options("${target}" PRIVATE /Od)

target_compile_options("${target}" PRIVATE /RTC1)
target_compile_options("${target}" PRIVATE /GS)
target_compile_options("${target}" PRIVATE /Zi) # /ZI edit/continue

target_link_options("${target}" PRIVATE /DEBUG)
#target_link_options("${target}" PRIVATE /ALIGN:16)
endif()

# Release
if (${CMAKE_BUILD_TYPE} MATCHES "Release")
#set_target_properties("${target}" PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)

target_compile_definitions("${target}" PRIVATE -DNDEBUG)

target_compile_options("${target}" PRIVATE /O2 /Os)
target_compile_options("${target}" PRIVATE /GS-)

target_link_options("${target}" PRIVATE /Release)
target_link_options("${target}" PRIVATE /INCREMENTAL:NO)


target_link_options("${target}" PRIVATE /OPT:REF /OPT:ICF)




# Undocumented options
target_link_options("${target}" PRIVATE /emittoolversioninfo:no /emitpogophaseinfo)

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/stub.bin)
target_link_options("${target}" PRIVATE /stub:${CMAKE_CURRENT_SOURCE_DIR}/stub.bin )
endif()
endif()




# Minimum Windows 10.
# target_compile_definitions(CMakeTest+1 PRIVATE -DWINVER=0x0a00)
# target_compile_definitions(CMakeTest+1 PRIVATE -D_WIN32_WINNT=0x0a00)

# Check if has manifest.txt then add one
target_link_options("${target}" PRIVATE /MANIFEST:NO)


target_link_options("${target}" PRIVATE /MAP:map.txt)


if(BUILD_SHARED_LIBS)
# Dynamic
if (${CMAKE_BUILD_TYPE} MATCHES "Release")
set_target_properties("${target}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
else()
set_target_properties("${target}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDebugDLL")
endif()
else()
# Static
if (${CMAKE_BUILD_TYPE} MATCHES "Release")
set_target_properties("${target}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreaded")
else()
set_target_properties("${target}" PROPERTIES MSVC_RUNTIME_LIBRARY "MultiThreadedDebug")
endif()
endif()


# Disabled warnings
target_compile_options("${target}" PRIVATE

/wd5039 # pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc.

/wd5262 # implicit fall-through occurs here; are you missing a break statement? Use [[fallthrough]] when a break
# statement is intentionally omitted between cases
)

endif() # MSVC

endfunction()
73 changes: 73 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#
cmake_minimum_required (VERSION 3.23)

set(CMAKE_DISABLE_SOURCE_CHANGES ON)
set(CMAKE_DISABLE_IN_SOURCE_BUILD ON)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "Do not build in-source. Please remove CMakeCache.txt and the CMakeFiles/ directory. Then build out-of-source.")
endif()

# buildinc.exe buildnumber.h $(ProjectName)

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMake")
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include(SetupMSVC)


set(PROJECT_VERSION 1.0.0)

message(STATUS "Path: " ${CMAKE_CURRENT_SOURCE_DIR}/src)


project(buildinc VERSION ${PROJECT_VERSION} LANGUAGES CXX)



# Buildinc
add_executable (buildinc)
setup_piku_executable_msvc(buildinc "")
target_include_directories(buildinc PRIVATE ${CMAKE_CURRENT_LIST_DIR}/src)


add_subdirectory(src)

target_compile_options(buildinc PRIVATE

/wd5039 # pointer or reference to potentially throwing function passed to 'extern "C"' function under -EHc.

/wd5262 # implicit fall-through occurs here; are you missing a break statement? Use [[fallthrough]] when a break
# statement is intentionally omitted between cases
/wd4710 # function not inlined
/wd4711 # function selected for automatic inline expansion
/wd5045 # Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified
)




if (${CMAKE_BUILD_TYPE} MATCHES "Release")

add_custom_command(TARGET buildinc
POST_BUILD
COMMENT Run BuildInc and copy to tools
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bin/buildinc.exe buildnumber.h BuildInc -q
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src
)


if(GLOBAL_TOOL)
if(EXISTS ${GLOBAL_TOOL})

add_custom_command(TARGET buildinc
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/bin/buildinc.exe" "${GLOBAL_TOOL}/buildinc.exe"
USES_TERMINAL
)
endif()
endif()



endif()
Loading

0 comments on commit fa2ee20

Please sign in to comment.