@@ -16,74 +16,109 @@ project(boost_handlebars LANGUAGES CXX)
1616set (BOOST_HANDLEBARS_MODULE_NAME "handlebars" )
1717
1818# Options
19- option (BOOST_HANDLEBARS_ENABLE_TESTS "Enable tests" ON )
19+ option (BOOST_HANDLEBARS_BUILD_TESTS "Build tests" ON )
2020
2121# Default build type
2222if (NOT CMAKE_BUILD_TYPE )
2323 set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type" FORCE)
2424endif ()
2525
26- # Collect source files
27- file (GLOB_RECURSE BOOST_HANDLEBARS_SOURCES CONFIGURE_DEPENDS
28- ${CMAKE_CURRENT_SOURCE_DIR} /src/*.cpp
29- source_file_names.cpp
30- )
31-
32- # Create library target
33- add_library (boost_handlebars ${BOOST_HANDLEBARS_SOURCES} )
34-
35- # C++ standard
36- target_compile_features (boost_handlebars PUBLIC cxx_std_23)
37-
38- # Include directories
39- target_include_directories (boost_handlebars
40- PUBLIC
41- $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
42- $<INSTALL_INTERFACE:include >
43- )
44-
45- # Shared build macro
46- target_compile_definitions (boost_handlebars
47- PRIVATE
26+ # Shared compiler settings
27+ set (BOOST_HANDLEBARS_CXX_STANDARD 23)
28+ set (BOOST_HANDLEBARS_COMPILE_DEFS
4829 -DBOOST_HANDLEBARS_STATIC_LINK
4930)
5031
51- if (WIN32 )
52- target_compile_definitions (
53- boost_handlebars
54- PUBLIC
32+ if (WIN32 )
33+ list (APPEND BOOST_HANDLEBARS_COMPILE_DEFS
5534 -D_WIN32_WINNT=0x0601
5635 -D_CRT_SECURE_NO_WARNINGS
5736 )
37+ endif ()
5838
59- if (MSVC )
60- target_compile_options (
61- boost_handlebars
62- PUBLIC
63- /permissive- # strict C++
64- /Zc:preprocessor # new preprocessor
65- /W4 # enable all warnings
66- /MP # multi-processor compilation
67- /EHs # C++ exception handling
68- $<$<CONFIG:Debug>:/Oy-> # disable frame pointer omission
69- )
70- endif ()
39+ # Shared include paths
40+ set (BOOST_HANDLEBARS_INCLUDE_DIRS
41+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} /include >
42+ $<INSTALL_INTERFACE:include >
43+ )
44+
45+ # Shared MSVC flags
46+ if (MSVC )
47+ set (BOOST_HANDLEBARS_MSVC_FLAGS
48+ /permissive-
49+ /Zc:preprocessor
50+ /W4
51+ /MP
52+ /EHs
53+ $<$<CONFIG:Debug>:/Oy->
54+ )
55+ endif ()
56+
57+ # --------------------------------------------------
58+ # Library target
59+ # --------------------------------------------------
60+
61+ file (GLOB_RECURSE BOOST_HANDLEBARS_SOURCES CONFIGURE_DEPENDS
62+ ${CMAKE_CURRENT_SOURCE_DIR} /src/*.cpp
63+ source_file_names.cpp
64+ )
65+
66+ add_library (boost_handlebars ${BOOST_HANDLEBARS_SOURCES} )
67+ target_compile_features (boost_handlebars PUBLIC cxx_std_${BOOST_HANDLEBARS_CXX_STANDARD} )
68+ target_compile_definitions (boost_handlebars PRIVATE ${BOOST_HANDLEBARS_COMPILE_DEFS} )
69+ target_include_directories (boost_handlebars PUBLIC
70+ ${BOOST_HANDLEBARS_INCLUDE_DIRS}
71+ $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >)
72+ if (MSVC )
73+ target_compile_options (boost_handlebars PUBLIC ${BOOST_HANDLEBARS_MSVC_FLAGS} )
7174endif ()
7275
7376# Install rules
7477include (GNUInstallDirs)
7578
7679install (TARGETS boost_handlebars
77- EXPORT boost_handlebars_targets
78- ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
79- LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
80- RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
80+ EXPORT boost_handlebars_targets
81+ ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
82+ LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
83+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
8184)
8285
8386install (DIRECTORY boost/handlebars
84- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /boost
87+ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} /boost
8588)
8689
87- # Tests
90+ # --------------------------------------------------
91+ # Unit tests
92+ # --------------------------------------------------
8893enable_testing ()
89- add_subdirectory (test )
94+
95+ if (BOOST_HANDLEBARS_BUILD_TESTS)
96+ include (CTest)
97+
98+ find_package (Boost REQUIRED COMPONENTS container)
99+
100+ file (GLOB_RECURSE BOOST_HANDLEBARS_TEST_SOURCES CONFIGURE_DEPENDS
101+ ${CMAKE_CURRENT_SOURCE_DIR} /test /*.cpp
102+ )
103+
104+ add_executable (handlebars-test ${BOOST_HANDLEBARS_TEST_SOURCES} )
105+ target_compile_features (handlebars-test PUBLIC cxx_std_${BOOST_HANDLEBARS_CXX_STANDARD} )
106+ target_link_libraries (handlebars-test PRIVATE
107+ Boost::container
108+ boost_handlebars)
109+ target_include_directories (handlebars-test PRIVATE
110+ ${BOOST_HANDLEBARS_INCLUDE_DIRS}
111+ ${CMAKE_CURRENT_SOURCE_DIR}
112+ )
113+ target_compile_definitions (handlebars-test PRIVATE
114+ ${BOOST_HANDLEBARS_COMPILE_DEFS}
115+ -DBOOST_HANDLEBARS_TEST_FILES_DIR="${CMAKE_CURRENT_SOURCE_DIR} /test/test-files"
116+ )
117+ if (MSVC )
118+ target_compile_options (handlebars-test PRIVATE ${BOOST_HANDLEBARS_MSVC_FLAGS} )
119+ target_compile_options (handlebars-test PRIVATE /bigobj)
120+ endif ()
121+
122+ add_test (NAME handlebars-unit-tests COMMAND handlebars-test )
123+ endif ()
124+
0 commit comments