Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

Commit 54de041

Browse files
author
Randall Britten
committed
Refactored common cmake settings.
DRY (Don't Repeat Yourself) principle: set flags in one place and reuse from other locations.
1 parent 799e632 commit 54de041

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

cmake/common.cmake

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
macro(INITIALISE_PROJECT)
2+
if(WIN32)
3+
set(CMAKE_CXX_FLAGS "/W3")
4+
else()
5+
set(CMAKE_CXX_FLAGS "-Wall -W -Werror")
6+
endif()
7+
8+
if (MSVC)
9+
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
10+
endif()
11+
12+
endmacro()

src/CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.cmake_minimum_required (VERSION 3.1)
1414

15+
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
1516

1617
set(CELLML_EXPORT_H "${CMAKE_CURRENT_BINARY_DIR}/api/libcellml/libcellml_export.h")
1718
set(LIBCELLML_CONFIG_H "${CMAKE_CURRENT_BINARY_DIR}/libcellml_config.h")
@@ -97,8 +98,4 @@ install(FILES
9798

9899
install(EXPORT libcellml-targets DESTINATION lib/cmake)
99100

100-
if (MSVC)
101-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
102-
endif()
103-
104101
set_target_properties(cellml PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)

tests/CMakeLists.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.cmake_minimum_required (VERSION 3.1)
1414

15+
INCLUDE(${CMAKE_SOURCE_DIR}/cmake/common.cmake)
16+
1517
# This adds another subdirectory, which has 'project(gtest)'.
1618
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/gtest-1.7.0)
1719

@@ -46,8 +48,4 @@ target_link_libraries(libcellmlTest cellml)
4648
# test executable.
4749
add_test(libcellmlTest libcellmlTest)
4850

49-
if (MSVC)
50-
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd /EHsc")
51-
endif()
52-
5351
set_target_properties(libcellmlTest PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)

0 commit comments

Comments
 (0)