-
Notifications
You must be signed in to change notification settings - Fork 120
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
CMake build script updates #140
Changes from all commits
083bb0c
486c1a7
82b3854
8d994a1
682db24
aae4195
a3704c5
008d195
abcf1da
57302ab
8511eb4
0ba88d0
f49f674
40524c1
9b1397f
ae8c75a
0f5aeb3
7e6a8b3
797f4a8
29a0119
5336cfa
8706615
42db87d
7db5c37
81a0093
01bc83a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_size = 4 | ||
tab_width = 4 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
build* | ||
*.swp | ||
*~ | ||
.gdb_history | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
cmake_minimum_required(VERSION 3.3) | ||
|
||
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
project(Seasocks VERSION 1.4.3) | ||
|
||
if(WIN32) | ||
message(FATAL_ERROR "${PROJECT_NAME} does not support Windows") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! |
||
endif() | ||
|
||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") | ||
|
||
option(SEASOCKS_SHARED "Build shared Seasocks library" ON) | ||
option(SEASOCKS_STATIC "Build static Seasocks library" ON) | ||
option(UNITTESTS "Build unittests." ON) | ||
option(COVERAGE "Build with code coverage enabled" OFF) | ||
option(SEASOCKS_EXAMPLE_APP "Build the example applications." ON) | ||
option(DEFLATE_SUPPORT "Include support for deflate (requires zlib)." ON) | ||
|
||
if (NOT SEASOCKS_SHARED AND NOT SEASOCKS_STATIC) | ||
message(FATAL_ERROR "SEASOCKS_SHARED and SEASOCKS_STATIC cannot both be false.") | ||
endif () | ||
|
||
if (DEFLATE_SUPPORT) | ||
set(DEFLATE_SUPPORT_BOOL "true") | ||
else () | ||
|
@@ -29,39 +37,45 @@ set(CMAKE_CXX_STANDARD 14) | |
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
|
||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.h.in internal/Config.h) | ||
include_directories(${CMAKE_CURRENT_BINARY_DIR}) | ||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Config.h.in internal/Config.h @ONLY) | ||
add_compile_options(-Wall -Werror -Wextra -pedantic -pedantic-errors) | ||
if (COVERAGE) | ||
add_compile_options(--coverage -O0) | ||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage") | ||
set(CMAKE_SHARED_LINKER_FLAGS "${SHARED_EXE_LINKER_FLAGS} --coverage") | ||
endif () | ||
|
||
find_package(Threads) | ||
find_package(PythonInterp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice, didn't know that package! 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's superseded by |
||
|
||
|
||
find_program(PYTHON_BIN NAMES python python3 DOC "Python executable") | ||
|
||
if (NOT PYTHON_BIN) | ||
if (NOT PYTHONINTERP_FOUND) | ||
message(SEND_ERROR "Python not found") | ||
else() | ||
message(STATUS "Using Python: '${PYTHON_BIN}'") | ||
message(STATUS "Using Python: '${PYTHON_EXECUTABLE}'") | ||
endif () | ||
|
||
if (DEFLATE_SUPPORT) | ||
find_package(ZLIB REQUIRED) | ||
endif () | ||
|
||
add_subdirectory("src") | ||
add_subdirectory(src) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. much nicer, thank you |
||
|
||
include(CMakePackageConfigHelpers) | ||
configure_package_config_file(cmake/SeasocksConfig.cmake.in ${PROJECT_NAME}Config.cmake | ||
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/" | ||
) | ||
write_basic_package_version_file( | ||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake | ||
VERSION ${PROJECT_VERSION} | ||
COMPATIBILITY SameMajorVersion | ||
) | ||
|
||
install(FILES | ||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake | ||
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake | ||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}/ | ||
) | ||
install(FILES | ||
LICENSE | ||
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${PROJECT_NAME}" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set(SEASOCKS_SHARED @SEASOCKS_SHARED@) | ||
set(SEASOCKS_STATIC @SEASOCKS_STATIC@) | ||
set(SEASOCKS_DEFLATE_SUPPORT @DEFLATE_SUPPORT@) | ||
|
||
if(SEASOCKS_STATIC) | ||
find_package(Threads REQUIRED) | ||
if(SEASOCKS_DEFLATE_SUPPORT) | ||
find_package(ZLIB REQUIRED) | ||
endif() | ||
endif() | ||
|
||
include("${CMAKE_CURRENT_LIST_DIR}/SeasocksTargets.cmake") | ||
|
||
@PACKAGE_INIT@ | ||
mattgodbolt marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from conans import CMake, ConanFile, tools | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm happy to have this here, but forgive my ignorance: how might this work to get seasocks in conan build center? Also it looks like we're missing a test_package -- have you been able to test that this seasocks build works? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't help at all for getting seasocks in cci, because it doesn't follow cci practices. In theory, now you can add a job on travis that uses this conanfile. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. I can't see that we'd ever use conan to build seasocks in this case (it has so few upstream dependencies). My projects that do have upstream deps do use conan, but I don't want to rely on it here. However, that doesn't mean this isn't super useful! We will definitely add a conan test job once this is working, how would you suggest doing so with your changes here?
Aside: I do so hate the multi-stage aspect of conan. In all my experience, if there are manual steps, then people will forget them! In my own projects I always use the conan.cmake file to make conan part of the build itself...I've spent too long debugging things like "oh, you forgot to conan install:? You're probably building against the old libraries...argh!") There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This requires adding new jobs, that will run the conan commands.
It's a matter of taste I guess. (Matt accidentally edited this comment; I hope I've un-edited back appropriate) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops! I meant to reply!!! Not edit your comment 😊 I tried to say: This requires adding new jobs, that will run the conan commands. I get that, just quickly, how might one actually build seasocks using conan? conan install .. && conan build .. && conan test .. like you mentioned above? Would that actually run the tests? Thanks again for teaching me this. I always try to make my project package manager agnostic. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was wrong there. The intended use of
Check the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try and work through that once we're merged in. I'm not quite following but I imagine trying to do it will elucidate more than reading dry documentation. |
||
from conans.errors import ConanException, ConanInvalidConfiguration | ||
import os | ||
import re | ||
import shutil | ||
import textwrap | ||
|
||
|
||
class SeasocksConan(ConanFile): | ||
name = "seasocks" | ||
def set_version(self): | ||
cmakelists = tools.load(os.path.join(self.recipe_folder, "CMakeLists.txt")) | ||
try: | ||
m = next(re.finditer(r"project\(Seasocks VERSION ([0-9.]+)\)", cmakelists)) | ||
except StopIteration: | ||
raise ConanException("Cannot detect Seasocks version from CMakeLists.txt") | ||
self.version = m.group(1) | ||
topics = ("seasocks", "embeddable", "webserver", "websockets") | ||
homepage = "https://github.com/mattgodbolt/seasocks" | ||
url = "https://github.com/mattgodbolt/seasocks" | ||
license = "BSD-2-Clause" | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = { | ||
"shared": [True, False], | ||
"static": [True, False], | ||
"fPIC": [True, False], | ||
mattgodbolt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"with_zlib": [True, False], | ||
} | ||
default_options = { | ||
"shared": True, | ||
"static": True, | ||
"fPIC": True, | ||
"with_zlib": True, | ||
} | ||
no_copy_source = True | ||
generators = "cmake", "cmake_find_package" | ||
|
||
def export_sources(self): | ||
shutil.copytree("cmake", os.path.join(self.export_sources_folder, "cmake")) | ||
shutil.copytree("scripts", os.path.join(self.export_sources_folder, "scripts")) | ||
shutil.copytree("src", os.path.join(self.export_sources_folder, "src")) | ||
shutil.copy("CMakeLists.txt", self.export_sources_folder) | ||
shutil.copy("LICENSE", self.export_sources_folder) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def configure(self): | ||
if not self.options.static: | ||
del self.options.fPIC | ||
if not any((self.options.shared, self.options.static)): | ||
raise ConanInvalidConfiguration("Need to build a shared and/or static library") | ||
|
||
def requirements(self): | ||
if self.options.with_zlib: | ||
self.requires("zlib/1.2.11") | ||
|
||
def build(self): | ||
if self.source_folder == self.build_folder: | ||
raise ConanException("Cannot build in same folder as sources") | ||
tools.save(os.path.join(self.build_folder, "CMakeLists.txt"), textwrap.dedent("""\ | ||
cmake_minimum_required(VERSION 3.0) | ||
project(cmake_wrapper) | ||
|
||
include("{install_folder}/conanbuildinfo.cmake") | ||
conan_basic_setup(TARGETS) | ||
|
||
add_subdirectory("{source_folder}" seasocks) | ||
""").format( | ||
source_folder=self.source_folder.replace("\\", "/"), | ||
install_folder=self.install_folder.replace("\\", "/"))) | ||
cmake = CMake(self) | ||
cmake.definitions["SEASOCKS_SHARED"] = self.options.shared | ||
cmake.definitions["SEASOCKS_STATIC"] = self.options.static | ||
cmake.definitions["DEFLATE_SUPPORT"] = self.options.with_zlib | ||
cmake.configure(source_folder=self.build_folder) | ||
cmake.build() | ||
|
||
def package(self): | ||
cmake = CMake(self) | ||
cmake.install() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
|
||
add_subdirectory("main/c") | ||
add_subdirectory("main/web") | ||
add_subdirectory(main/c) | ||
add_subdirectory(main/web) | ||
|
||
macro(add_seasocks_executable _name) | ||
add_library(${_name}_objs OBJECT ${ARGN}) | ||
target_link_libraries(${_name}_objs PRIVATE seasocks_headers) | ||
if (TARGET seasocks) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat way of doing this! |
||
add_executable(${_name} $<TARGET_OBJECTS:${_name}_objs>) | ||
target_link_libraries(${_name} PRIVATE seasocks) | ||
endif () | ||
if (TARGET seasocks_so) | ||
add_executable(${_name}_so $<TARGET_OBJECTS:${_name}_objs>) | ||
target_link_libraries(${_name}_so PRIVATE seasocks_so) | ||
endif () | ||
endmacro() | ||
|
||
macro(seasocks_link_libraries _name) | ||
target_link_libraries(${_name}_objs ${ARGN}) | ||
endmacro() | ||
|
||
if (SEASOCKS_EXAMPLE_APP) | ||
add_subdirectory("app/c") | ||
add_subdirectory(app/c) | ||
endif () | ||
|
||
if (UNITTESTS) | ||
find_program(CMAKE_MEMORYCHECK_COMMAND valgrind) | ||
enable_testing() | ||
add_subdirectory("test/c") | ||
add_subdirectory(test/c) | ||
endif () | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Mac OS should be included too? Test for not-linux?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, test should include
APPLE