Skip to content

Commit

Permalink
Cleanup CMakeLists a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
chocolacula committed Nov 2, 2023
1 parent c9bdaad commit ab78a1f
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 47 deletions.
31 changes: 12 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,32 +1,22 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

include(cmake/tools.cmake)
update_submodule(vcpkg)
set_policies()

set(CMAKE_TOOLCHAIN_FILE vcpkg/scripts/buildsystems/vcpkg.cmake)

cmake_policy(SET CMP0091 NEW)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

cmake_policy(SET CMP0075 NEW)

# Get version from vcpkg.json manifest
find_program(PYTHON "python3")
if(NOT PYTHON)
find_program(PYTHON "python")
endif()
file(READ "${CMAKE_SOURCE_DIR}/vcpkg.json" VCPKG_MANIFEST_JSON)

if(NOT PYTHON)
message(WARNING "Python is not found")
endif()

execute_process(COMMAND ${PYTHON} ${CMAKE_SOURCE_DIR}/version.py
get -f ${CMAKE_SOURCE_DIR}/vcpkg.json
OUTPUT_VARIABLE VCPKG_MANIFEST_PROJECT_VERSION
ERROR_VARIABLE VCPKG_VERSION_ERROR)
string(JSON
VCPKG_MANIFEST_PROJECT_VERSION
ERROR_VARIABLE VCPKG_VERSION_ERROR
GET ${VCPKG_MANIFEST_JSON} "version")

if(VCPKG_VERSION_ERROR)
message(WARNING ${VCPKG_VERSION_ERROR})
set(VCPKG_MANIFEST_PROJECT_VERSION "0.0.0")
endif()

# Enable vcpkg features
Expand All @@ -45,9 +35,12 @@ if(ENABLE_BENCHMARKS)
endif()

# Setup project
cmake_policy(SET CMP0048 NEW)
project(easy_reflection VERSION ${VCPKG_MANIFEST_PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

include(Dart)
enable_testing()

Expand Down
6 changes: 1 addition & 5 deletions benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

project(benchmarks VERSION ${CMAKE_PROJECT_VERSION})

add_definitions(-DPROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

disable_attribute_warnings()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
Expand Down
8 changes: 8 additions & 0 deletions cmake/tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ function(disable_attribute_warnings)
endif()
endfunction()

# Helper function to set all policies
function(set_policies)
cmake_policy(SET CMP0075 NEW) # required library macro
cmake_policy(SET CMP0048 NEW) # project version
cmake_policy(SET CMP0091 NEW) # MSVC runtime library
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endfunction()

# Print variables that match the optional parameter.
# Arguments:
# FILTER - print only variables matching this string, print all if it's empty
Expand Down
6 changes: 1 addition & 5 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

project(example VERSION ${CMAKE_PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

disable_attribute_warnings()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
Expand Down
6 changes: 1 addition & 5 deletions generator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

project(er_gen VERSION ${CMAKE_PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

if(MSVC)
add_compile_options("$<$<NOT:$<CONFIG:DEBUG>>:/Ox>")
else()
Expand Down
5 changes: 1 addition & 4 deletions library/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

project(reflection VERSION ${CMAKE_PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

include_directories(include)

set(SOURCES
Expand Down
3 changes: 0 additions & 3 deletions readme/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Visual Studio CMake generators do not create `compile_commands.json`. However, y
To build `er_gen` and use reflection on Windows, make sure to install the following dependencies and add them to your `PATH`:

- Git
- Python
- CMake
- Ninja

Expand All @@ -47,8 +46,6 @@ This repository includes a `Dockerfile` that sets up an `Ubuntu 22.04` environme

Another submodule is [vcpkg](https://github.com/microsoft/vcpkg) which manages most of the dependencies, all of them will be installed by CMake automatically.

> **Note:** You need **Python** to obtain project version from `vcpkg.json` manifest file. You probably already have it, please install it otherwise.
After installing all the dependencies, you need to decide whether you want to use `simdjson` for parsing or not. While `simdjson` provides the fastest performance on supported hardware, `rapidjson` might be faster in virtual environments. The solution includes a native parser that is available regardless. It offers more flexibility when it comes to map parsing but not as fast.

If, for some reason, you want to exclude `simdjson` from the dependencies, you can use the following **CMake** option:
Expand Down
6 changes: 1 addition & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
cmake_minimum_required(VERSION 3.10)
cmake_minimum_required(VERSION 3.19)

project(tests VERSION ${CMAKE_PROJECT_VERSION})

add_definitions(-DPROJECT_ROOT="${CMAKE_CURRENT_SOURCE_DIR}")
add_definitions(-DREPEATS=1000)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})

disable_attribute_warnings()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/output)
Expand Down
2 changes: 1 addition & 1 deletion vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reflection-cpp",
"version": "3.0.0",
"version": "3.1.0",
"default-features": [
"library"
],
Expand Down

0 comments on commit ab78a1f

Please sign in to comment.