1 # CMake based on work from @xantares
2 cmake_minimum_required (VERSION 3.1.0)
3 set(CMAKE_CXX_STANDARD 11)
4 set(CMAKE_CXX_STANDARD_REQUIRED ON)
6 # By default, build in Release mode. Must appear before project() command
7 if (NOT DEFINED CMAKE_BUILD_TYPE)
8 set (CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
11 project(muParserProject)
15 # Bump versions on release
16 set(MUPARSER_VERSION_MAJOR 2)
17 set(MUPARSER_VERSION_MINOR 3)
18 set(MUPARSER_VERSION_PATCH 2)
19 set(MUPARSER_VERSION ${MUPARSER_VERSION_MAJOR}.${MUPARSER_VERSION_MINOR}.${MUPARSER_VERSION_PATCH})
22 #option(ENABLE_SAMPLES "Build the samples" ON)
23 #option(ENABLE_OPENMP "Enable OpenMP for multithreading" ON)
24 set(ENABLE_OPENMP ${GMX_OPENMP})
25 option(BUILD_SHARED_LIBS "Build shared/static libs" ON)
28 find_package(OpenMP REQUIRED)
29 set(CMAKE_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_CXX_FLAGS}")
30 set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "${OpenMP_CXX_FLAGS} ${CMAKE_SHARED_LIBRARY_CXX_FLAGS}")
34 # Credit: https://stackoverflow.com/questions/2368811/how-to-set-warning-level-in-cmake/3818084
36 # Force to always compile with W4
37 if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
38 string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
40 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
42 elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
44 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-long-long -pedantic")
47 # include_directories("${CMAKE_CURRENT_SOURCE_DIR}/include")
50 src/muParserBytecode.cpp
51 src/muParserCallback.cpp
57 src/muParserTokenReader.cpp
59 target_include_directories(muparser SYSTEM PUBLIC
60 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>)
62 # this compiles the "DLL" interface (C API)
63 target_compile_definitions(muparser PRIVATE MUPARSER_DLL)
65 if (BUILD_SHARED_LIBS)
66 target_compile_definitions(muparser PRIVATE MUPARSERLIB_EXPORTS)
68 target_compile_definitions(muparser PUBLIC MUPARSER_STATIC)
71 if (CMAKE_BUILD_TYPE STREQUAL Debug)
72 target_compile_definitions(muparser PRIVATE _DEBUG)
76 target_compile_definitions(muparser PRIVATE MUP_USE_OPENMP)
78 set_target_properties(muparser PROPERTIES
79 VERSION ${MUPARSER_VERSION}
80 SOVERSION ${MUPARSER_VERSION_MAJOR}
83 # Install the export set for use with the install-tree
84 export(TARGETS muparser FILE "${CMAKE_BINARY_DIR}/muparser-targets.cmake")
87 add_executable(example1 samples/example1/example1.cpp)
88 target_link_libraries(example1 muparser)
90 add_executable(example2 samples/example2/example2.c)
91 target_link_libraries(example2 muparser)
94 # The GNUInstallDirs defines ${CMAKE_INSTALL_DATAROOTDIR}
95 # See https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
96 include (GNUInstallDirs)
98 install(TARGETS muparser
99 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT RuntimeLibraries
100 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT Development
101 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT RuntimeLibraries
105 include/muParserBase.h
106 include/muParserBytecode.h
107 include/muParserCallback.h
108 include/muParserDef.h
109 include/muParserDLL.h
110 include/muParserError.h
111 include/muParserFixes.h
113 include/muParserInt.h
114 include/muParserTemplateMagic.h
115 include/muParserTest.h
116 include/muParserToken.h
117 include/muParserTokenReader.h
119 COMPONENT Development
122 # Define variables for the pkg-config file
123 set(PACKAGE_NAME muparser)
126 ${CMAKE_BINARY_DIR}/muparser.pc
130 FILES ${CMAKE_BINARY_DIR}/muparser.pc
131 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig
137 add_executable (t_ParserTest test/t_ParserTest.cpp)
138 target_link_libraries(t_ParserTest muparser)
140 target_link_libraries(t_ParserTest OpenMP::OpenMP_CXX)
142 add_test (NAME ParserTest COMMAND t_ParserTest)
143 add_dependencies(tests t_ParserTest)