diff --git a/CMakeLists.txt b/CMakeLists.txt index e1efa6b..96d262a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,18 +2,20 @@ # LP3_MAIN # Simplifies writing game "lp3-main.cpp" files. # ********************************************************************* -project(lp3-main CXX) cmake_minimum_required(VERSION 3.9.0 FATAL_ERROR) -include(CMakePackageConfigHelpers) -enable_testing() +if(NOT DEFINED PROJECT_NAME) + set(NOT_SUBPROJECT ON) +endif() -include("${CMAKE_BINARY_DIR}/conan_paths.cmake" OPTIONAL - RESULT_VARIABLE using_conan) +project(lp3-main CXX) -if(using_conan) - set(CMAKE_FIND_PACKAGE_PREFER_CONFIG TRUE) -endif() +include(CTest) +include(CMakePackageConfigHelpers) + +# Allow user to ask explicitly to build tests +option(LP3_MAIN_Build_Tests "Build tests when BUILD_TESTING is enabled." + ${NOT_SUBPROJECT}) add_library( lp3-main @@ -54,6 +56,52 @@ else() PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/pc/platform.cpp) endif() +# ********************************************************************* +# Tests and Drivers / Demos +# ********************************************************************* + +if(BUILD_TESTING AND LP3_MAIN_Build_Tests) + find_package(Catch2 REQUIRED) + + function(make_test exe_target) + if("${CMAKE_SYSTEM_NAME}" MATCHES "Emscripten") + add_test(NAME "test_${exe_target}" COMMAND node + $) + else() + add_test(NAME "test_${exe_target}" COMMAND ${exe_target}) + endif() + endfunction() + + add_executable(ExitDemo WIN32 + ${CMAKE_CURRENT_SOURCE_DIR}/demos/ExitDemo.cpp) + target_link_libraries(ExitDemo lp3-main) + make_test(ExitDemo) + + add_executable(MainDemo WIN32 + ${CMAKE_CURRENT_SOURCE_DIR}/demos/MainDemo.cpp) + target_link_libraries(MainDemo lp3-main) + + add_executable(WinConsoleTest + ${CMAKE_CURRENT_SOURCE_DIR}/demos/WinConsoleTest.cpp) + target_link_libraries(WinConsoleTest lp3-main) + make_test(WinConsoleTest) + + if(LP3_SETUP_FOLDERS) + set_target_properties(lp3-main PROPERTIES FOLDER lp3-main) + set_target_properties(ExitDemo PROPERTIES FOLDER lp3-main) + set_target_properties(MainDemo PROPERTIES FOLDER lp3-main) + set_target_properties(WinConsoleTest PROPERTIES FOLDER lp3-main) + endif() + + if(BUILD_SHARED_LIBS) + if(MSVC) + target_compile_options(ExitDemo PRIVATE /wd4251 /wd4275) + target_compile_options(MainDemo PRIVATE /wd4251 /wd4275) + target_compile_options(WinConsoleTest PRIVATE /wd4251 /wd4275) + endif() + endif() +endif() + # ********************************************************************* # Package / Install Stuff # ********************************************************************* @@ -91,51 +139,3 @@ write_basic_package_version_file( install(FILES "${PROJECT_BINARY_DIR}/lp3-mainConfig.cmake" "${PROJECT_BINARY_DIR}/lp3-mainConfigVersion.cmake" DESTINATION lib/cmake/lp3-main) - -# ********************************************************************* -# Tests and Drivers / Demos -# ********************************************************************* - -get_directory_property(is_child PARENT_DIRECTORY) -if(NOT is_child) - set(LP3_MAIN_FULL True) -endif() - -function(make_test exe_target) - if("${CMAKE_SYSTEM_NAME}" MATCHES "Emscripten") - add_test(NAME "test_${exe_target}" COMMAND node - $) - else() - add_test(NAME "test_${exe_target}" COMMAND ${exe_target}) - endif() -endfunction() - -if(LP3_MAIN_FULL) - add_executable(ExitDemo WIN32 - ${CMAKE_CURRENT_SOURCE_DIR}/demos/ExitDemo.cpp) - target_link_libraries(ExitDemo lp3-main) - make_test(ExitDemo) - - add_executable(MainDemo WIN32 - ${CMAKE_CURRENT_SOURCE_DIR}/demos/MainDemo.cpp) - target_link_libraries(MainDemo lp3-main) - - add_executable(WinConsoleTest - ${CMAKE_CURRENT_SOURCE_DIR}/demos/WinConsoleTest.cpp) - target_link_libraries(WinConsoleTest lp3-main) - make_test(WinConsoleTest) - - if(LP3_SETUP_FOLDERS) - set_target_properties(lp3-main PROPERTIES FOLDER lp3-main) - set_target_properties(ExitDemo PROPERTIES FOLDER lp3-main) - set_target_properties(MainDemo PROPERTIES FOLDER lp3-main) - set_target_properties(WinConsoleTest PROPERTIES FOLDER lp3-main) - endif() - if(BUILD_SHARED_LIBS) - if(MSVC) - target_compile_options(ExitDemo PRIVATE /wd4251 /wd4275) - target_compile_options(MainDemo PRIVATE /wd4251 /wd4275) - target_compile_options(WinConsoleTest PRIVATE /wd4251 /wd4275) - endif() - endif() -endif() diff --git a/changelog.md b/changelog.md index 0b4e425..09b9bc6 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # Change Log +### 1.0.5 2020-06-20 + +Only builds tests / drivers if BUILD_TESTING and LP3_MAIN_Build_Tests is set. This is to avoid building and running tests when creating recipes. It also keeps test dependencies out of the build requirements. + ### 1.0.4 2020-06-19 find_package name changed The CMake targets have changed to the following: diff --git a/conanfile.py b/conanfile.py index d892757..b3268db 100644 --- a/conanfile.py +++ b/conanfile.py @@ -5,7 +5,7 @@ class Lp3Main(conans.ConanFile): name = "Lp3-Main" - version = "1.0.4" + version = "1.0.5" license = "Zlib" author = "Tim Simpson" url = "https://github.com/TimSimpson/Lp3-Main" @@ -17,10 +17,25 @@ class Lp3Main(conans.ConanFile): requires = tuple() - build_requires = ( - "catch2/2.4.1@bincrafters/stable" - ) - generators = "cmake_paths", "cmake_find_package" + build_requires = [] + + test_requires = [ + "Catch2/2.11.1@catchorg/stable", + ] + + @property + def tests_enabled(self): + return ( + self.develop + and (os.environ.get("CONAN_SKIP_TESTS") or "").lower() != 'true' + ) + + def build_requirements(self): + if self.tests_enabled: + for tr in self.test_requires: + self.build_requires(tr) + + generators = "cmake_find_package" exports_sources = ( "src/*", "include/*", "demos/*", "tests/*", "CMakeLists.txt" @@ -29,37 +44,18 @@ class Lp3Main(conans.ConanFile): def _configed_cmake(self): cmake = conans.CMake(self) cmake.configure(defs={ - "CMAKE_FIND_PACKAGE_PREFER_CONFIG":"TRUE", + "LP3_MAIN_Build_Tests": self.tests_enabled, }) return cmake def build(self): cmake = self._configed_cmake() cmake.build() - # # If SDL2 is shared, we won't be able to find it in most cases. - # #if self.settings.os != "Emscripten" and not self.options.shared: - # cmake.test() def package(self): cmake = self._configed_cmake() cmake.install() - # self.copy("*.hpp", dst="include", src="src") - # self.copy("*.lib", dst="lib", keep_path=False) - # self.copy("*.dll", dst="bin", keep_path=False) - # self.copy("*.dylib*", dst="lib", keep_path=False) - # self.copy("*.so", dst="lib", keep_path=False) - # self.copy("*.a", dst="lib", keep_path=False) - # self.copy("Lp3_Main-config*.cmake", dst="lib/cmake", keep_path=False) - def package_info(self): self.cpp_info.name = "lp3-main" self.cpp_info.libs = [ "lp3-main" ] - # self.cpp_info.libs = ["lp3-main"] - # # self.cpp_info.names["cmake_find_package"] = "Lp3-Main" - # # self.cpp_info.names["cmake_find_package_multi"] = "Lp3" - # self.cpp_info.components["main"].names["cmake"] = "main" - # self.cpp_info.components["main"].names["cmake_find_package"] = "main" - # self.cpp_info.components["main"].names["cmake_find_package_multi"] = "main" - # self.cpp_info.components["main"].includedirs = ["include"] - # self.cpp_info.components["main"].libs = ["lp3-main"]