Skip to content
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

Get rid of CMake export headers #41

Merged
merged 1 commit into from
Jan 7, 2022
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
13 changes: 5 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ cmake_minimum_required(VERSION 3.8 FATAL_ERROR)

project(Zycore VERSION 1.1.0.0 LANGUAGES C CXX)

include(GenerateExportHeader)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

Expand Down Expand Up @@ -112,22 +111,23 @@ if (ZYCORE_BUILD_SHARED_LIB)
add_library("Zycore" SHARED)
else ()
add_library("Zycore" STATIC)
target_compile_definitions("Zycore" PUBLIC "ZYCORE_STATIC_BUILD")
endif ()

set_target_properties("Zycore" PROPERTIES
LINKER_LANGUAGE C
VERSION ${Zycore_VERSION}
SOVERSION ${Zycore_VERSION_MAJOR}.${Zycore_VERSION_MINOR})
VERSION "${Zycore_VERSION}"
SOVERSION "${Zycore_VERSION_MAJOR}.${Zycore_VERSION_MINOR}"
DEFINE_SYMBOL "ZYCORE_SHOULD_EXPORT")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This renames the default of Zycore_EXPORTS -> ZYCORE_SHOULD_EXPORT.

target_include_directories("Zycore"
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE "src")
target_compile_definitions("Zycore" PRIVATE "_CRT_SECURE_NO_WARNINGS" "ZYCORE_EXPORTS")
target_compile_definitions("Zycore" PRIVATE "_CRT_SECURE_NO_WARNINGS")
zyan_set_common_flags("Zycore")
zyan_maybe_enable_wpo_for_lib("Zycore")
generate_export_header("Zycore" BASE_NAME "ZYCORE" EXPORT_FILE_NAME "ZycoreExportConfig.h")

if (ZYAN_NO_LIBC)
target_compile_definitions("Zycore" PUBLIC "ZYAN_NO_LIBC")
Expand Down Expand Up @@ -207,9 +207,6 @@ install(TARGETS "Zycore" EXPORT "zycore-targets")
install(EXPORT "zycore-targets"
NAMESPACE "Zycore::"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/zycore")
install(FILES
"${PROJECT_BINARY_DIR}/ZycoreExportConfig.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
install(DIRECTORY "include/" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# =============================================================================================== #
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/API/Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_API_MEMORY_H
#define ZYCORE_API_MEMORY_H

#include <ZycoreExportConfig.h>
#include <Zycore/Defines.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/API/Process.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_API_PROCESS_H
#define ZYCORE_API_PROCESS_H

#include <ZycoreExportConfig.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>

Expand Down
1 change: 0 additions & 1 deletion include/Zycore/API/Synchronization.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_API_SYNCHRONIZATION_H
#define ZYCORE_API_SYNCHRONIZATION_H

#include <ZycoreExportConfig.h>
#include <Zycore/Defines.h>
#include <Zycore/Status.h>

Expand Down
1 change: 0 additions & 1 deletion include/Zycore/API/Terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_API_TERMINAL_H
#define ZYCORE_API_TERMINAL_H

#include <ZycoreExportConfig.h>
#include <Zycore/LibC.h>
#include <Zycore/Status.h>

Expand Down
1 change: 0 additions & 1 deletion include/Zycore/API/Thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_API_THREAD_H
#define ZYCORE_API_THREAD_H

#include <ZycoreExportConfig.h>
#include <Zycore/Defines.h>
#include <Zycore/Status.h>

Expand Down
1 change: 0 additions & 1 deletion include/Zycore/Allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_ALLOCATOR_H
#define ZYCORE_ALLOCATOR_H

#include <ZycoreExportConfig.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>

Expand Down
1 change: 0 additions & 1 deletion include/Zycore/Bitset.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_BITSET_H
#define ZYCORE_BITSET_H

#include <ZycoreExportConfig.h>
#include <Zycore/Allocator.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
Expand Down
67 changes: 67 additions & 0 deletions include/Zycore/Defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,73 @@
# define ZYAN_RELEASE
#endif

/* ============================================================================================== */
/* Deprecation hint */
/* ============================================================================================== */

#if defined(ZYAN_GCC) || defined(ZYAN_CLANG)
# define ZYAN_DEPRECATED __attribute__((__deprecated__))
#elif defined(ZYAN_MSVC)
# define ZYAN_DEPRECATED __declspec(deprecated)
#else
# define ZYAN_DEPRECATED
#endif

/* ============================================================================================== */
/* Generic DLL import/export helpers */
/* ============================================================================================== */

#if defined(ZYAN_MSVC)
# define ZYAN_DLLEXPORT __declspec(dllexport)
# define ZYAN_DLLIMPORT __declspec(dllimport)
#else
# define ZYAN_DLLEXPORT
# define ZYAN_DLLIMPORT
#endif

/* ============================================================================================== */
/* Zycore dll{export,import} */
/* ============================================================================================== */

// This is a cut-down version of what CMake's `GenerateExportHeader` would usually generate. To
// simplify builds without CMake, we define these things manually instead of relying on CMake
// to generate the header.
//
// For static builds, our CMakeList will define `ZYCORE_STATIC_BUILD`. For shared library builds,
// our CMake will define `ZYCORE_SHOULD_EXPORT` depending on whether the target is being imported or
// exported. If CMake isn't used, users can manually define these to fit their use-case.

// Backward compatibility: CMake would previously generate these variables names. However, because
// they have pretty cryptic names, we renamed them when we got rid of `GenerateExportHeader`. For
// backward compatibility for users that don't use CMake and previously manually defined these, we
// translate the old defines here and print a warning.
#if defined(ZYCORE_STATIC_DEFINE)
# pragma message("ZYCORE_STATIC_DEFINE was renamed to ZYCORE_STATIC_BUILD.")
# define ZYCORE_STATIC_BUILD
#endif
#if defined(Zycore_EXPORTS)
# pragma message("Zycore_EXPORTS was renamed to ZYCORE_SHOULD_EXPORT.")
# define ZYCORE_SHOULD_EXPORT
#endif

/**
* Symbol is exported in shared library builds.
*/
#if defined(ZYCORE_STATIC_BUILD)
# define ZYCORE_EXPORT
#else
# if defined(ZYCORE_SHOULD_EXPORT)
# define ZYCORE_EXPORT ZYAN_DLLEXPORT
# else
# define ZYCORE_EXPORT ZYAN_DLLIMPORT
# endif
#endif

/**
* Symbol is not exported and for internal use only.
*/
#define ZYCORE_NO_EXPORT

/* ============================================================================================== */
/* Misc compatibility macros */
/* ============================================================================================== */
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/Format.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_FORMAT_H
#define ZYCORE_FORMAT_H

#include <ZycoreExportConfig.h>
#include <Zycore/Status.h>
#include <Zycore/String.h>
#include <Zycore/Types.h>
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/List.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_LIST_H
#define ZYCORE_LIST_H

#include <ZycoreExportConfig.h>
#include <Zycore/Allocator.h>
#include <Zycore/Object.h>
#include <Zycore/Status.h>
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/String.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_STRING_H
#define ZYCORE_STRING_H

#include <ZycoreExportConfig.h>
#include <Zycore/Allocator.h>
#include <Zycore/Status.h>
#include <Zycore/Types.h>
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_VECTOR_H
#define ZYCORE_VECTOR_H

#include <ZycoreExportConfig.h>
#include <Zycore/Allocator.h>
#include <Zycore/Comparison.h>
#include <Zycore/Object.h>
Expand Down
1 change: 0 additions & 1 deletion include/Zycore/Zycore.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
#ifndef ZYCORE_H
#define ZYCORE_H

#include <ZycoreExportConfig.h>
#include <Zycore/Types.h>

// TODO:
Expand Down