Skip to content

Commit

Permalink
build: optimze build (#60)
Browse files Browse the repository at this point in the history
- update baseline and cmake-modules.
- remove some useless cmake build instructions and optimize heaeder-only layout.
  • Loading branch information
msclock committed Mar 5, 2024
1 parent 03afcf8 commit b99bd6b
Show file tree
Hide file tree
Showing 18 changed files with 50 additions and 84 deletions.
36 changes: 9 additions & 27 deletions src/compile/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,12 @@ target_code_coverage(${target_name}-shared ALL)

include(GenerateExportHeader)
generate_export_header(
${target_name}-shared
BASE_NAME
"${target_name}"
EXPORT_MACRO_NAME
"${target_name}_EXPORT"
EXPORT_FILE_NAME
${target_name}-shared BASE_NAME "${target_name}" EXPORT_FILE_NAME
"${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}/${target_name}_export.hpp"
DEPRECATED_MACRO_NAME
"${target_name}_DEPRECATED"
NO_EXPORT_MACRO_NAME
"${target_name}_NO_EXPORT"
STATIC_DEFINE
"${target_name}_STATIC_DEFINE"
NO_DEPRECATED_MACRO_NAME
"${target_name}_NO_DEPRECATED"
DEFINE_NO_DEPRECATED)
)

target_sources(${target_name}-shared PRIVATE ${_srcs} ${_hdrs})

target_compile_definitions(${target_name}-shared
INTERFACE $<INSTALL_INTERFACE:USING_${target_name}>)

target_include_interface_directories(
${target_name}-shared ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include)
Expand Down Expand Up @@ -62,10 +46,8 @@ target_code_coverage(${target_name}-static ALL)

target_sources(${target_name}-static PRIVATE ${_srcs} ${_hdrs})

target_compile_definitions(
${target_name}-static
PUBLIC ${target_name}_STATIC_DEFINE
INTERFACE $<INSTALL_INTERFACE:USING_${target_name}>)
target_compile_definitions(${target_name}-static
INTERFACE ${target_name}_STATIC_DEFINE)

target_include_interface_directories(
${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
Expand All @@ -81,11 +63,8 @@ target_link_libraries(
PRIVATE msft_proxy
PRIVATE absl::log)

set_target_properties(
${target_name}-static
PROPERTIES POSITION_INDEPENDENT_CODE 1
ARCHIVE_OUTPUT_NAME "${target_name}_s"
RELEASE_POSTFIX "_s")
set_target_properties(${target_name}-static PROPERTIES ARCHIVE_OUTPUT_NAME
"${target_name}")

# msvc layout in solution
source_group("impl" REGULAR_EXPRESSION "impl/.*\\.[h|cpp]")
Expand Down Expand Up @@ -116,8 +95,11 @@ install_target(
msft_proxy
absl::log)

install_dependency(TARGETS ${target_name}-shared ${target_name}-static)

# Tests
message(STATUS "BUILD_TESTING:${BUILD_TESTING}")

if(BUILD_TESTING)
add_subdirectory(tests)
endif()
7 changes: 3 additions & 4 deletions src/compile/include/compile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ namespace info {
/**
* \brief Get compile version string
* \return The distribution compile version provided.
* \note A string "dev" will be returned when no version configuration.
*/
std::string_view compile_EXPORT version_compile() noexcept;
std::string_view COMPILE_EXPORT version_compile() noexcept;

/**
* \return A bool represents if debug when building.
* \return A bool represents if it is debug distribution.
*/
bool compile_EXPORT is_debug() noexcept;
bool COMPILE_EXPORT is_debug() noexcept;
}; // namespace info
}; // namespace compile
10 changes: 5 additions & 5 deletions src/compile/include/impl/impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace geo {
// https://devblogs.microsoft.com/cppblog/proxy-runtime-polymorphism-made-easier-than-ever/

// Abstraction Draw interface for polymorphic call
struct compile_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
struct COMPILE_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
public:
template <class T>
void operator()(const T& self, std::ostream& out) {
Expand All @@ -24,7 +24,7 @@ struct compile_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
};

// Abstraction Area interface for polymorphic call
struct compile_EXPORT Area : pro::dispatch<double()> {
struct COMPILE_EXPORT Area : pro::dispatch<double()> {
public:
template <class T>
double operator()(const T& self) {
Expand All @@ -33,13 +33,13 @@ struct compile_EXPORT Area : pro::dispatch<double()> {
};

// Interface facade for Draw, Area
struct compile_EXPORT DrawableFacade : pro::facade<Draw, Area> {};
struct COMPILE_EXPORT DrawableFacade : pro::facade<Draw, Area> {};

// Client API - Consumer
std::string compile_EXPORT PrintDrawableToString(const pro::proxy<DrawableFacade>& p);
std::string COMPILE_EXPORT PrintDrawableToString(const pro::proxy<DrawableFacade>& p);

// Client API - Producer
pro::proxy<DrawableFacade> compile_EXPORT CreateRectangleAsDrawable(int width, int height);
pro::proxy<DrawableFacade> COMPILE_EXPORT CreateRectangleAsDrawable(int width, int height);

}; // namespace geo
}; // namespace compile
3 changes: 2 additions & 1 deletion src/compile/src/compile.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "compile.hpp"

#include <absl/log/log.h>
#include "git.h"
#include "impl/impl.hpp"
Expand All @@ -9,7 +10,7 @@ std::string_view version_compile() noexcept {
return git::ProjectVersion();
}

bool compile_EXPORT is_debug() noexcept {
bool is_debug() noexcept {
#ifdef _DEBUG
return true;
#else
Expand Down
1 change: 1 addition & 0 deletions src/compile/src/impl/impl.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "impl/impl.hpp"

#include <sstream>

namespace compile {
Expand Down
2 changes: 1 addition & 1 deletion src/header_only/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install_target(
TARGETS
${target_name}
INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/include/${target_name}/
${CMAKE_BINARY_DIR}/git/include/
LICENSE_FILE_LIST
${CMAKE_SOURCE_DIR}/LICENSE
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/header_only/tests/test_header_only.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "header_only.hpp"
#include "header_only/header_only.hpp"

TEST(common, some_fun) {
const auto fun_ret = header_only::common::some_fun();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,12 @@ target_code_coverage(${target_name}-shared ALL)

include(GenerateExportHeader)
generate_export_header(
${target_name}-shared
BASE_NAME
"${target_name}"
EXPORT_MACRO_NAME
"${target_name}_EXPORT"
EXPORT_FILE_NAME
${target_name}-shared BASE_NAME "${target_name}" EXPORT_FILE_NAME
"${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}/${target_name}_export.hpp"
DEPRECATED_MACRO_NAME
"${target_name}_DEPRECATED"
NO_EXPORT_MACRO_NAME
"${target_name}_NO_EXPORT"
STATIC_DEFINE
"${target_name}_STATIC_DEFINE"
NO_DEPRECATED_MACRO_NAME
"${target_name}_NO_DEPRECATED"
DEFINE_NO_DEPRECATED)
)

target_sources(${target_name}-shared PRIVATE ${_srcs} ${_hdrs})

target_compile_definitions(${target_name}-shared
INTERFACE $<INSTALL_INTERFACE:USING_${target_name}>)

target_include_interface_directories(
${target_name}-shared ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
${CMAKE_CURRENT_SOURCE_DIR}/include ${CMAKE_BINARY_DIR}/git/include)
Expand Down Expand Up @@ -62,10 +46,8 @@ target_code_coverage(${target_name}-static ALL)

target_sources(${target_name}-static PRIVATE ${_srcs} ${_hdrs})

target_compile_definitions(
${target_name}-static
PUBLIC ${target_name}_STATIC_DEFINE
INTERFACE $<INSTALL_INTERFACE:USING_${target_name}>)
target_compile_definitions(${target_name}-static
INTERFACE ${target_name}_STATIC_DEFINE)

target_include_interface_directories(
${target_name}-static ${CMAKE_CURRENT_BINARY_DIR}/include/${target_name}
Expand All @@ -81,11 +63,8 @@ target_link_libraries(
PRIVATE msft_proxy
PRIVATE absl::log)

set_target_properties(
${target_name}-static
PROPERTIES POSITION_INDEPENDENT_CODE 1
ARCHIVE_OUTPUT_NAME "${target_name}_s"
RELEASE_POSTFIX "_s")
set_target_properties(${target_name}-static PROPERTIES ARCHIVE_OUTPUT_NAME
"${target_name}")

# msvc layout in solution
source_group("impl" REGULAR_EXPRESSION "impl/.*\\.[h|cpp]")
Expand Down Expand Up @@ -116,8 +95,11 @@ install_target(
msft_proxy
absl::log)

install_dependency(TARGETS ${target_name}-shared ${target_name}-static)

# Tests
message(STATUS "BUILD_TESTING:${BUILD_TESTING}")

if(BUILD_TESTING)
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ namespace info {
/**
* \brief Get compile version string
* \return The distribution compile version provided.
* \note A string "dev" will be returned when no version configuration.
*/
std::string_view compile_EXPORT version_compile() noexcept;
std::string_view COMPILE_EXPORT version_compile() noexcept;

/**
* \return A bool represents if debug when building.
* \return A bool represents if it is debug distribution.
*/
bool compile_EXPORT is_debug() noexcept;
bool COMPILE_EXPORT is_debug() noexcept;
}; // namespace info
}; // namespace compile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace geo {
// https://devblogs.microsoft.com/cppblog/proxy-runtime-polymorphism-made-easier-than-ever/

// Abstraction Draw interface for polymorphic call
struct compile_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
struct COMPILE_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
public:
template <class T>
void operator()(const T& self, std::ostream& out) {
Expand All @@ -24,7 +24,7 @@ struct compile_EXPORT Draw : pro::dispatch<void(std::ostream&)> {
};

// Abstraction Area interface for polymorphic call
struct compile_EXPORT Area : pro::dispatch<double()> {
struct COMPILE_EXPORT Area : pro::dispatch<double()> {
public:
template <class T>
double operator()(const T& self) {
Expand All @@ -33,13 +33,13 @@ struct compile_EXPORT Area : pro::dispatch<double()> {
};

// Interface facade for Draw, Area
struct compile_EXPORT DrawableFacade : pro::facade<Draw, Area> {};
struct COMPILE_EXPORT DrawableFacade : pro::facade<Draw, Area> {};

// Client API - Consumer
std::string compile_EXPORT PrintDrawableToString(const pro::proxy<DrawableFacade>& p);
std::string COMPILE_EXPORT PrintDrawableToString(const pro::proxy<DrawableFacade>& p);

// Client API - Producer
pro::proxy<DrawableFacade> compile_EXPORT CreateRectangleAsDrawable(int width, int height);
pro::proxy<DrawableFacade> COMPILE_EXPORT CreateRectangleAsDrawable(int width, int height);

}; // namespace geo
}; // namespace compile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "compile.hpp"

#include <absl/log/log.h>
#include "git.h"
#include "impl/impl.hpp"
Expand All @@ -9,7 +10,7 @@ std::string_view version_compile() noexcept {
return git::ProjectVersion();
}

bool compile_EXPORT is_debug() noexcept {
bool is_debug() noexcept {
#ifdef _DEBUG
return true;
#else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "impl/impl.hpp"

#include <sstream>

namespace compile {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ install_target(
TARGETS
${target_name}
INCLUDES
${CMAKE_CURRENT_SOURCE_DIR}/include/
${CMAKE_CURRENT_SOURCE_DIR}/include/${target_name}/
${CMAKE_BINARY_DIR}/git/include/
LICENSE_FILE_LIST
${CMAKE_SOURCE_DIR}/LICENSE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <gtest/gtest.h>
#include "header_only.hpp"
#include "header_only/header_only.hpp"

TEST(common, some_fun) {
const auto fun_ret = header_only::common::some_fun();
Expand Down
6 changes: 3 additions & 3 deletions template/vcpkg.json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "{{ repo_name }}",
"description": "{{ project_description }}",
"builtin-baseline": "80403036a665cb8fcc1a1b3e17593d20b03b2489",
"builtin-baseline": "710677da49b03885c65c8b5ca43072d4b1acde75",
"dependencies": [
[%- if add_compile_target == true or add_executable_target == true or add_header_only_target == true %]
"abseil",
Expand Down Expand Up @@ -46,7 +46,7 @@
[%- endif %]
{
"name": "cmake-modules",
"version": "1.3.0"
"version": "1.3.6"
},
{
"name": "robotology-cmake-ycm",
Expand All @@ -57,7 +57,7 @@
"registries": [
{
"kind": "git",
"baseline": "b58077c46126bee7c5cd54c26a4b974055c21d2b",
"baseline": "8166fd34bde37098afa04b82b0ec7f2a2f467fe3",
"repository": "https://github.com/msclock/cmake-registry",
"packages": [
[%- if use_conan == true %]
Expand Down
6 changes: 3 additions & 3 deletions vcpkg.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg.schema.json",
"name": "ss-cpp",
"description": "A development-focused Cpp project template.",
"builtin-baseline": "80403036a665cb8fcc1a1b3e17593d20b03b2489",
"builtin-baseline": "710677da49b03885c65c8b5ca43072d4b1acde75",
"dependencies": [
"abseil",
"proxy",
Expand All @@ -20,7 +20,7 @@
},
{
"name": "cmake-modules",
"version": "1.3.0"
"version": "1.3.6"
},
{
"name": "robotology-cmake-ycm",
Expand All @@ -31,7 +31,7 @@
"registries": [
{
"kind": "git",
"baseline": "b58077c46126bee7c5cd54c26a4b974055c21d2b",
"baseline": "8166fd34bde37098afa04b82b0ec7f2a2f467fe3",
"repository": "https://github.com/msclock/cmake-registry",
"packages": [
"cmake-modules",
Expand Down

0 comments on commit b99bd6b

Please sign in to comment.