Skip to content

Specialized target defaults #86

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion buildcc/lib/target/include/target/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class Target {
const fs::path &absolute_output_path);

// * Headers
void AddHeader(const std::string &relative_filename,
void AddHeader(const fs::path &relative_filename,
const fs::path &relative_to_target_path = "");
void AddHeaderAbsolute(const fs::path &absolute_filepath);

Expand Down
2 changes: 1 addition & 1 deletion buildcc/lib/target/src/target/include_dir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void Target::AddHeaderAbsolute(const fs::path &absolute_filepath) {
internal::add_path(absolute_filepath, current_header_files_);
}

void Target::AddHeader(const std::string &relative_filename,
void Target::AddHeader(const fs::path &relative_filename,
const fs::path &relative_to_target_path) {
env::log_trace(name_, __FUNCTION__);

Expand Down
2 changes: 0 additions & 2 deletions buildcc/targets/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
set(TARGET_SPECIALIZED_SRCS
include/targets/target_constants.h
include/targets/target_gcc.h
include/targets/target_msvc.h
include/targets/target_generic.h
include/targets/target_custom.h
include/targets/target_utils.h
)

if(${BUILDCC_BUILD_AS_SINGLE_LIB})
Expand Down
70 changes: 0 additions & 70 deletions buildcc/targets/include/targets/target_constants.h

This file was deleted.

6 changes: 1 addition & 5 deletions buildcc/targets/include/targets/target_custom.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
#ifndef TARGETS_TARGET_CUSTOM_H_
#define TARGETS_TARGET_CUSTOM_H_

#include "target_constants.h"
#include "target_utils.h"

namespace buildcc {

class Target_custom : public base::Target {
Expand All @@ -28,8 +25,7 @@ class Target_custom : public base::Target {
const base::Toolchain &toolchain,
const std::filesystem::path &target_path_relative_to_root,
std::string_view compile_command, std::string_view link_command)
: Target(Name(name, type, toolchain), type, toolchain,
target_path_relative_to_root) {
: Target(name, type, toolchain, target_path_relative_to_root) {
compile_command_ = compile_command;
link_command_ = link_command;
}
Expand Down
23 changes: 21 additions & 2 deletions buildcc/targets/include/targets/target_gcc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,30 @@

#include "target/target.h"

#include "target_constants.h"

// TODO, Combine all of these into Target_gcc
namespace buildcc {

// Extensions
constexpr std::string_view kGccStaticLibExt = ".a";
constexpr std::string_view kGccDynamicLibExt = ".so";

// GCC
constexpr std::string_view kGccPrefixIncludeDir = "-I";
constexpr std::string_view kGccPrefixLibDir = "-L";
constexpr std::string_view kGccGenericCompileCommand =
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} -o "
"{output} -c {input}";
constexpr std::string_view kGccExecutableLinkCommand =
"{cpp_compiler} {link_flags} {compiled_sources} -o {output} "
"{lib_dirs} {lib_deps}";
constexpr std::string_view kGccStaticLibLinkCommand =
"{archiver} rcs {output} {compiled_sources}";
constexpr std::string_view kGccDynamicLibCompileCommand =
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} "
"-fpic -o {output} -c {input}";
constexpr std::string_view kGccDynamicLibLinkCommand =
"{cpp_compiler} -shared {link_flags} {compiled_sources} -o {output}";

class ExecutableTarget_gcc : public base::Target {
public:
ExecutableTarget_gcc(
Expand Down
6 changes: 2 additions & 4 deletions buildcc/targets/include/targets/target_generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "target_gcc.h"
#include "target_msvc.h"

#include "target_constants.h"
#include "target_utils.h"

namespace buildcc {

struct SyncTargetOptions {
Expand Down Expand Up @@ -189,7 +186,8 @@ class Target_generic : public base::Target {
env::assert_fatal(false, "Compiler ID not supported");
break;
}
SyncTargets(*this, *target, {
SyncTargets(*this, *target,
{
.c_compile_flags_ = true,
.cpp_compile_flags_ = true,
.link_flags_ = true,
Expand Down
48 changes: 36 additions & 12 deletions buildcc/targets/include/targets/target_msvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,39 @@

#include "target/target.h"

#include "target_constants.h"

// TODO, Combine all of these into Target_msvc
namespace buildcc {

inline void DefaultMsvcFlags(base::Target &target) {
// MSVC Constants
constexpr std::string_view kMsvcExecutableExt = ".exe";
constexpr std::string_view kMsvcStaticLibExt = ".lib";
// Why is `kWinDynamicLibExt != .dll` but `.lib` instead?
// See `kMsvcDynamicLibLinkCommand`
// IMPLIB .lib stubs are what is linked during link time
// OUT .dll needs to be present in the executable folder during runtime
constexpr std::string_view kMsvcDynamicLibExt = ".lib";

constexpr std::string_view kMsvcObjExt = ".obj";
constexpr std::string_view kMsvcPrefixIncludeDir = "/I";
constexpr std::string_view kMsvcPrefixLibDir = "/LIBPATH:";
// TODO, Split this into individual CompileCommands if any differences occur
constexpr std::string_view kMsvcCompileCommand =
"{compiler} {preprocessor_flags} {include_dirs} {compile_flags} "
"/Fo{output} /c {input}";
constexpr std::string_view kMsvcExecutableLinkCommand =
"{linker} {link_flags} {lib_dirs} /OUT:{output} {lib_deps} "
"{compiled_sources}";
constexpr std::string_view kMsvcStaticLibLinkCommand =
"{archiver} {link_flags} /OUT:{output} {compiled_sources}";
constexpr std::string_view kMsvcDynamicLibLinkCommand =
"{linker} /DLL {link_flags} /OUT:{output}.dll /IMPLIB:{output} "
"{compiled_sources}";

inline void DefaultMsvcOptions(base::Target &target) {
target.obj_ext_ = kMsvcObjExt;
target.prefix_include_dir_ = kMsvcPrefixIncludeDir;
target.prefix_lib_dir_ = kMsvcPrefixLibDir;

target.AddCCompileFlag("/nologo");
target.AddCppCompileFlag("/nologo");
target.AddCppCompileFlag("/EHsc"); // TODO, Might need to remove this
Expand All @@ -38,11 +65,10 @@ class ExecutableTarget_msvc : public base::Target {
const std::filesystem::path &target_path_relative_to_root)
: Target(name, base::TargetType::Executable, toolchain,
target_path_relative_to_root) {
prefix_include_dir_ = kMsvcPrefixIncludeDir;
prefix_lib_dir_ = kMsvcPrefixLibDir;
target_ext_ = kMsvcExecutableExt;
compile_command_ = kMsvcCompileCommand;
link_command_ = kMsvcExecutableLinkCommand;
DefaultMsvcFlags(*this);
DefaultMsvcOptions(*this);
}
};

Expand All @@ -52,11 +78,10 @@ class StaticTarget_msvc : public base::Target {
const std::filesystem::path &target_path_relative_to_root)
: Target(name, base::TargetType::StaticLibrary, toolchain,
target_path_relative_to_root) {
prefix_include_dir_ = kMsvcPrefixIncludeDir;
prefix_lib_dir_ = kMsvcPrefixLibDir;
target_ext_ = kMsvcStaticLibExt;
compile_command_ = kMsvcCompileCommand;
link_command_ = kMsvcStaticLibLinkCommand;
DefaultMsvcFlags(*this);
DefaultMsvcOptions(*this);
}
};

Expand All @@ -66,11 +91,10 @@ class DynamicTarget_msvc : public base::Target {
const std::filesystem::path &target_path_relative_to_root)
: Target(name, base::TargetType::DynamicLibrary, toolchain,
target_path_relative_to_root) {
prefix_include_dir_ = kMsvcPrefixIncludeDir;
prefix_lib_dir_ = kMsvcPrefixLibDir;
target_ext_ = kMsvcDynamicLibExt;
compile_command_ = kMsvcCompileCommand;
link_command_ = kMsvcDynamicLibLinkCommand;
DefaultMsvcFlags(*this);
DefaultMsvcOptions(*this);
}
};

Expand Down
79 changes: 0 additions & 79 deletions buildcc/targets/include/targets/target_utils.h

This file was deleted.