From ae845c69df1544f7d686cbced0f60581a91f82bd Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 20 Jun 2024 23:55:17 +0200 Subject: [PATCH] Simplify cmake.toml conditions --- .gitattributes | 3 + CMakeLists.txt | 112 +++++++++++++++++++------------------- cmake.toml | 42 +++++++------- cmkr.cmake | 2 +- thirdparty/CMakeLists.txt | 4 +- thirdparty/cmake.toml | 9 ++- 6 files changed, 89 insertions(+), 83 deletions(-) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1a139ac --- /dev/null +++ b/.gitattributes @@ -0,0 +1,3 @@ +# cmkr +/**/CMakeLists.txt linguist-generated +/**/cmkr.cmake linguist-vendored diff --git a/CMakeLists.txt b/CMakeLists.txt index 71b1ca4..f3e288e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,11 +1,7 @@ # This file is automatically generated from cmake.toml - DO NOT EDIT # See https://github.com/build-cpp/cmkr for more information -cmake_minimum_required(VERSION 3.15) - -# Enable support for MSVC_RUNTIME_LIBRARY -cmake_policy(SET CMP0091 NEW) -set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +cmake_minimum_required(VERSION 3.25) if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) message(FATAL_ERROR "In-tree builds are not supported. Run CMake from a separate directory: cmake -B build") @@ -28,10 +24,16 @@ if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR) configure_file(cmake.toml cmake.toml COPYONLY) endif() +# Enable support for MSVC_RUNTIME_LIBRARY +cmake_policy(SET CMP0091 NEW) +if(NOT DEFINED CMAKE_MSVC_RUNTIME_LIBRARY) + set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") +endif() + # Options -option(ZASM_BUILD_TESTS "" OFF) -option(ZASM_BUILD_BENCHMARKS "" OFF) -option(ZASM_BUILD_EXAMPLES "" OFF) +option(ZASM_BUILD_TESTS "" ${CMKR_ROOT_PROJECT}) +option(ZASM_BUILD_BENCHMARKS "" ${CMKR_ROOT_PROJECT}) +option(ZASM_BUILD_EXAMPLES "" ${CMKR_ROOT_PROJECT}) project(zasm LANGUAGES @@ -67,28 +69,7 @@ endif() # Target: zasm set(zasm_SOURCES - "zasm/src/zasm/src/core/error.cpp" - "zasm/src/zasm/src/core/filestream.cpp" - "zasm/src/zasm/src/core/memorystream.cpp" - "zasm/src/zasm/src/decoder/decoder.cpp" - "zasm/src/zasm/src/encoder/encoder.cpp" - "zasm/src/zasm/src/formatter/formatter.cpp" - "zasm/src/zasm/src/program/data.cpp" - "zasm/src/zasm/src/program/instruction.cpp" - "zasm/src/zasm/src/program/program.cpp" - "zasm/src/zasm/src/program/register.cpp" - "zasm/src/zasm/src/program/saverestore.cpp" - "zasm/src/zasm/src/program/saverestore.load.cpp" - "zasm/src/zasm/src/program/saverestore.save.cpp" - "zasm/src/zasm/src/serialization/serializer.cpp" - "zasm/src/zasm/src/x86/x86.assembler.cpp" - "zasm/src/zasm/src/x86/x86.register.cpp" - "zasm/src/zasm/src/zasm.cpp" - "zasm/src/zasm/src/encoder/encoder.context.hpp" - "zasm/src/zasm/src/program/program.node.hpp" - "zasm/src/zasm/src/program/program.state.hpp" - "zasm/src/zasm/src/program/saverestorehelper.hpp" - "zasm/src/zasm/src/program/saverestoretypes.hpp" + cmake.toml "zasm/include/zasm/base/immediate.hpp" "zasm/include/zasm/base/instruction.hpp" "zasm/include/zasm/base/label.hpp" @@ -132,7 +113,28 @@ set(zasm_SOURCES "zasm/include/zasm/x86/register.hpp" "zasm/include/zasm/x86/x86.hpp" "zasm/include/zasm/zasm.hpp" - cmake.toml + "zasm/src/zasm/src/core/error.cpp" + "zasm/src/zasm/src/core/filestream.cpp" + "zasm/src/zasm/src/core/memorystream.cpp" + "zasm/src/zasm/src/decoder/decoder.cpp" + "zasm/src/zasm/src/encoder/encoder.context.hpp" + "zasm/src/zasm/src/encoder/encoder.cpp" + "zasm/src/zasm/src/formatter/formatter.cpp" + "zasm/src/zasm/src/program/data.cpp" + "zasm/src/zasm/src/program/instruction.cpp" + "zasm/src/zasm/src/program/program.cpp" + "zasm/src/zasm/src/program/program.node.hpp" + "zasm/src/zasm/src/program/program.state.hpp" + "zasm/src/zasm/src/program/register.cpp" + "zasm/src/zasm/src/program/saverestore.cpp" + "zasm/src/zasm/src/program/saverestore.load.cpp" + "zasm/src/zasm/src/program/saverestore.save.cpp" + "zasm/src/zasm/src/program/saverestorehelper.hpp" + "zasm/src/zasm/src/program/saverestoretypes.hpp" + "zasm/src/zasm/src/serialization/serializer.cpp" + "zasm/src/zasm/src/x86/x86.assembler.cpp" + "zasm/src/zasm/src/x86/x86.register.cpp" + "zasm/src/zasm/src/zasm.cpp" ) add_library(zasm STATIC) @@ -151,7 +153,7 @@ target_link_libraries(zasm PUBLIC ) # Target: zasm_testdata -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_TESTS) # build-tests add_library(zasm_testdata INTERFACE) add_library(zasm::testdata ALIAS zasm_testdata) @@ -161,8 +163,9 @@ if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests endif() # Target: zasm_tests -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_TESTS) # build-tests set(zasm_tests_SOURCES + cmake.toml "tests/src/main.cpp" "tests/src/tests/tests.assembler.cpp" "tests/src/tests/tests.decoder.cpp" @@ -185,7 +188,6 @@ if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests "tests/src/tests/tests.stringpool.cpp" "tests/src/testutils.cpp" "tests/src/testutils.hpp" - cmake.toml ) add_executable(zasm_tests) @@ -212,7 +214,7 @@ if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests endif() # Target: zasm_benchmarks -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_BENCHMARKS) # build-benchmarks set(zasm_benchmarks_SOURCES "benchmark/src/benchmarks/benchmark.assembler.cpp" "benchmark/src/benchmarks/benchmark.formatter.cpp" @@ -247,7 +249,7 @@ if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests endif() # Target: zasm_example_common -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples add_library(zasm_example_common INTERFACE) add_library(zasm::examples::common ALIAS zasm_example_common) @@ -262,10 +264,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_assembler_basic -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_assembler_basic_SOURCES - "examples/assembler_basic/main.cpp" cmake.toml + "examples/assembler_basic/main.cpp" ) add_executable(zasm_example_assembler_basic) @@ -293,10 +295,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_assembler_sections -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_assembler_sections_SOURCES - "examples/assembler_sections/main.cpp" cmake.toml + "examples/assembler_sections/main.cpp" ) add_executable(zasm_example_assembler_sections) @@ -324,10 +326,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_decode_to_assembler -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_decode_to_assembler_SOURCES - "examples/decode_to_assembler/main.cpp" cmake.toml + "examples/decode_to_assembler/main.cpp" ) add_executable(zasm_example_decode_to_assembler) @@ -355,10 +357,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_program_observer -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_program_observer_SOURCES - "examples/program_observer/main.cpp" cmake.toml + "examples/program_observer/main.cpp" ) add_executable(zasm_example_program_observer) @@ -386,10 +388,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_instruction_info -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_instruction_info_SOURCES - "examples/instruction_info/main.cpp" cmake.toml + "examples/instruction_info/main.cpp" ) add_executable(zasm_example_instruction_info) @@ -417,10 +419,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_modify_program -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_modify_program_SOURCES - "examples/modify_program/main.cpp" cmake.toml + "examples/modify_program/main.cpp" ) add_executable(zasm_example_modify_program) @@ -448,10 +450,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_basic_jit -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_basic_jit_SOURCES - "examples/basic_jit/main.cpp" cmake.toml + "examples/basic_jit/main.cpp" ) add_executable(zasm_example_basic_jit) @@ -479,10 +481,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_modify_instruction -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_modify_instruction_SOURCES - "examples/modify_instruction/main.cpp" cmake.toml + "examples/modify_instruction/main.cpp" ) add_executable(zasm_example_modify_instruction) @@ -510,10 +512,10 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() # Target: zasm_example_memory_operands -if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples +if(ZASM_BUILD_EXAMPLES) # build-examples set(zasm_example_memory_operands_SOURCES - "examples/memory_operands/main.cpp" cmake.toml + "examples/memory_operands/main.cpp" ) add_executable(zasm_example_memory_operands) @@ -542,7 +544,7 @@ if(ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT) # examples endif() enable_testing() -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_TESTS) # build-tests add_test( NAME tests diff --git a/cmake.toml b/cmake.toml index cf2ddee..3d9d458 100644 --- a/cmake.toml +++ b/cmake.toml @@ -1,18 +1,16 @@ # Reference: https://build-cpp.github.io/cmkr/cmake-toml +[cmake] +version = "3.25" + [project] name = "zasm" languages = ["CXX"] msvc-runtime = "static" [options] -ZASM_BUILD_TESTS = false -ZASM_BUILD_BENCHMARKS = false -ZASM_BUILD_EXAMPLES = false - -[conditions] -tests = "ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT" -benchmarks = "ZASM_BUILD_BENCHMARKS OR CMKR_ROOT_PROJECT" -examples = "ZASM_BUILD_EXAMPLES OR CMKR_ROOT_PROJECT" +ZASM_BUILD_TESTS = "root" +ZASM_BUILD_BENCHMARKS = "root" +ZASM_BUILD_EXAMPLES = "root" [subdir.thirdparty] @@ -39,13 +37,13 @@ link-libraries = [ ] [target.zasm_testdata] -condition = "tests" +condition = "build-tests" type = "interface" alias = "zasm::testdata" include-directories = ["testdata/include"] [target.zasm_tests] -condition = "tests" +condition = "build-tests" type = "executable" sources = [ "tests/src/**.cpp", @@ -63,7 +61,7 @@ link-libraries = [ PROJECT_LABEL = "tests" [target.zasm_benchmarks] -condition = "tests" +condition = "build-benchmarks" type = "executable" sources = [ "benchmark/src/**.cpp", @@ -81,7 +79,7 @@ link-libraries = [ PROJECT_LABEL = "benchmarks" [target.zasm_example_common] -condition = "examples" +condition = "build-examples" type = "interface" alias = "zasm::examples::common" include-directories = ["examples/common"] @@ -92,7 +90,7 @@ link-libraries = [ ## Examples [target.zasm_example_assembler_basic] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/assembler_basic/main.cpp"] link-libraries = [ @@ -104,7 +102,7 @@ PROJECT_LABEL = "assembler_basic" RUNTIME_OUTPUT_NAME = "example.assembler_basic" [target.zasm_example_assembler_sections] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/assembler_sections/main.cpp"] link-libraries = [ @@ -116,7 +114,7 @@ PROJECT_LABEL = "assembler_sections" RUNTIME_OUTPUT_NAME = "example.assembler_sections" [target.zasm_example_decode_to_assembler] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/decode_to_assembler/main.cpp"] link-libraries = [ @@ -128,7 +126,7 @@ PROJECT_LABEL = "decode_to_assembler" RUNTIME_OUTPUT_NAME = "example.decode_to_assembler" [target.zasm_example_program_observer] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/program_observer/main.cpp"] link-libraries = [ @@ -140,7 +138,7 @@ PROJECT_LABEL = "program_observer" RUNTIME_OUTPUT_NAME = "example.program_observer" [target.zasm_example_instruction_info] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/instruction_info/main.cpp"] link-libraries = [ @@ -152,7 +150,7 @@ PROJECT_LABEL = "instruction_info" RUNTIME_OUTPUT_NAME = "example.instruction_info" [target.zasm_example_modify_program] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/modify_program/main.cpp"] link-libraries = [ @@ -164,7 +162,7 @@ PROJECT_LABEL = "modify_program" RUNTIME_OUTPUT_NAME = "example.modify_program" [target.zasm_example_basic_jit] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/basic_jit/main.cpp"] link-libraries = [ @@ -176,7 +174,7 @@ PROJECT_LABEL = "basic_jit" RUNTIME_OUTPUT_NAME = "example.basic_jit" [target.zasm_example_modify_instruction] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/modify_instruction/main.cpp"] link-libraries = [ @@ -188,7 +186,7 @@ PROJECT_LABEL = "modify_instruction" RUNTIME_OUTPUT_NAME = "example.modify_instruction" [target.zasm_example_memory_operands] -condition = "examples" +condition = "build-examples" type = "executable" sources = ["examples/memory_operands/main.cpp"] link-libraries = [ @@ -200,6 +198,6 @@ PROJECT_LABEL = "memory_operands" RUNTIME_OUTPUT_NAME = "example.memory_operands" [[test]] -condition = "tests" +condition = "build-tests" name = "tests" command = "$" diff --git a/cmkr.cmake b/cmkr.cmake index cdeea6e..26ef6fa 100644 --- a/cmkr.cmake +++ b/cmkr.cmake @@ -2,7 +2,7 @@ include_guard() # Change these defaults to point to your infrastructure if desired set(CMKR_REPO "https://github.com/build-cpp/cmkr" CACHE STRING "cmkr git repository" FORCE) -set(CMKR_TAG "v0.2.26" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) +set(CMKR_TAG "v0.2.31" CACHE STRING "cmkr git tag (this needs to be available forever)" FORCE) set(CMKR_COMMIT_HASH "" CACHE STRING "cmkr git commit hash (optional)" FORCE) # To bootstrap/generate a cmkr project: cmake -P cmkr.cmake diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index cbe5fde..c004128 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -28,7 +28,7 @@ FetchContent_Declare(Zydis SYSTEM ) FetchContent_MakeAvailable(Zydis) -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_TESTS) # build-tests message(STATUS "Fetching GTest (release-1.11.0)...") FetchContent_Declare(GTest SYSTEM GIT_REPOSITORY @@ -39,7 +39,7 @@ if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests FetchContent_MakeAvailable(GTest) endif() -if(ZASM_BUILD_TESTS OR CMKR_ROOT_PROJECT) # tests +if(ZASM_BUILD_BENCHMARKS) # build-benchmarks message(STATUS "Fetching GBenchmark (v1.6.1)...") FetchContent_Declare(GBenchmark SYSTEM GIT_REPOSITORY diff --git a/thirdparty/cmake.toml b/thirdparty/cmake.toml index 63463cc..b03f847 100644 --- a/thirdparty/cmake.toml +++ b/thirdparty/cmake.toml @@ -10,13 +10,16 @@ BENCHMARK_USE_BUNDLED_GTEST = false [fetch-content.Zydis] git = "https://github.com/zyantific/zydis" tag = "v4.1.0" +system = true [fetch-content.GTest] -condition = "tests" +condition = "build-tests" git = "https://github.com/google/googletest" tag = "release-1.11.0" +system = true [fetch-content.GBenchmark] -condition = "tests" +condition = "build-benchmarks" git = "https://github.com/google/benchmark" -tag = "v1.6.1" \ No newline at end of file +tag = "v1.6.1" +system = true \ No newline at end of file